Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ cp -RL www/* $CUSTOM_ASSETS $DEST/
# Assemble base CSS modules followed by flavor customizations
node scripts/assemble-css.js "$DEST/style.css" $CUSTOM_CSS

# Compile the API docs into structure and per-locale message catalogs
node scripts/build-api-docs.js docs/api.md docs/i18n $DEST

# Open search (requires absolute CANONICAL_URL)
if [ -n "$CANONICAL_URL" ]; then
pug client/opensearch.pug -E xml -o $DEST
Expand Down
167 changes: 159 additions & 8 deletions client/src/app.js

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions client/src/components/code-block.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { CopyIcon } from './icons'

// Fallback for code without build-time highlighting (e.g. live responses):
// double-quoted strings are highlighted and JSON object keys are left plain.
const stringToken = /"(?:[^"\\\n]|\\.)*"(\s*:)?/g

const highlightStrings = code => {
const parts = []
let last = 0, match
while ((match = stringToken.exec(code))) {
if (match[1]) continue
parts.push(code.slice(last, match.index), <span className="hljs-string">{match[0]}</span>)
last = match.index + match[0].length
}
parts.push(code.slice(last))
return parts
}

const entities = { '&amp;': '&', '&lt;': '<', '&gt;': '>', '&quot;': '"', '&#x27;': "'", '&#39;': "'" }

const htmlText = html => html.replace(/<[^>]+>/g, '').replace(/&(amp|lt|gt|quot|#x27|#39);/g, entity => entities[entity])

// Pass either plain `code` or pre-highlighted `html`.
export const CodeBlock = ({ code, html, title, meta, copyLabel = 'Copy code' }) =>
<div className="code-block">
{ title || meta ? <div className="code-block-header">
{ title ? <h4 className="code-block-title">{title}</h4> : '' }
{ meta ? <span className="code-block-meta">{meta}</span> : '' }
</div> : '' }
<div className="code-block-body">
{ html
? <pre><code props={{ innerHTML: html }}></code></pre>
: <pre><code>{highlightStrings(code)}</code></pre> }
<button className="table-copy-button code-button-btn code-block-copy" type="button" data-clipboardCopy={html ? htmlText(html) : code} aria-label={copyLabel}>
<CopyIcon />
</button>
</div>
</div>
23 changes: 23 additions & 0 deletions client/src/components/code-tabs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { CodeBlock } from './code-block'

// items: [{ label, code or html }]. Selecting a tab emits its label via data-code-tab.
// children render below the code, inside the same box.
export const CodeTabs = ({ items, selected, title, meta, copyLabel, children = [] }) => {
const active = items.find(item => item.label == selected) || items[0]
return <div className="code-tabs">
<div className="code-tabs-header">
<div className="code-tabs-list" attrs={{ role: 'tablist' }}>
{ items.map(item =>
<button type="button" className={`code-tabs-tab${item == active ? ' active' : ''}`}
attrs={{ role: 'tab', 'aria-selected': String(item == active) }} data-codeTab={item.label}>
{item.label}
</button>) }
</div>
{ meta ? <span className="code-tabs-meta">{meta}</span> : '' }
</div>
<div className="code-tabs-body">
{ CodeBlock({ code: active.code, html: active.html, title, copyLabel }) }
{ children }
</div>
</div>
}
5 changes: 5 additions & 0 deletions client/src/components/icons.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions client/src/components/method-badge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const MethodBadge = ({ method }) =>
<span className={`method-badge method-badge-${method.toLowerCase()}`}>{method}</span>
24 changes: 24 additions & 0 deletions client/src/components/params-table.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// rows: [{ name, optional, in, type, descHtml }]
export const ParamsTable = ({ t, rows }) => {
const showIn = rows.some(row => row.in)
return <div className="params-table">
<div className={`params-table-row params-table-head${showIn ? ' with-in' : ''}`}>
<span>{t`Name`}</span>
{ showIn ? <span>{t`In`}</span> : '' }
<span>{t`Type`}</span>
<span>{t`Description`}</span>
</div>
{ rows.map(row =>
<div className={`params-table-row${showIn ? ' with-in' : ''}`}>
<span className="params-table-name">
<code>{row.name}</code>
<span className={row.optional ? 'params-table-optional' : 'params-table-required'}>
{row.optional ? t`Optional` : t`Required`}
</span>
</span>
{ showIn ? <span className="params-table-in">{row.in}</span> : '' }
<span className="params-table-type">{row.type}</span>
<span className="params-table-desc" props={{ innerHTML: row.descHtml }}></span>
</div>) }
</div>
}
32 changes: 32 additions & 0 deletions client/src/lib/api-docs-search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
export const docsPages = docs => docs.groups.flatMap(group =>
group.sections.flatMap(section => section.pages.map(page => ({ group, section, page }))))

export const docsPageTitle = (page, messages) => page.titleMsg ? messages[page.titleMsg] : page.rpc

const htmlText = html => html.replace(/<[^>]+>/g, ' ').replace(/&[a-z0-9#]+;/gi, ' ')

// Mirrors the standalone docs: pages with curated keywords use them, endpoints
// fall back to their summary.
export const buildDocsSearchIndex = (docs, messages) => docsPages(docs).map(({ group, section, page }) => {
const summary = page.blocks.find(block => block.type == 'prose')
return {
id: page.id,
enterpriseOnly: !!group.enterpriseOnly,
s: [ docsPageTitle(page, messages), page.path, messages[section.titleMsg] ].filter(Boolean).join(' ').toLowerCase(),
k: (messages[`${page.id}.keywords`] || (summary ? htmlText(messages[summary.msg]) : '')).toLowerCase()
}
})

// Every word must match. Title and path matches rank ahead of keyword matches.
export const searchDocs = (index, query) => {
const words = query.trim().toLowerCase().split(/\s+/).filter(Boolean)
if (!words.length) return null

const inTitle = entry => words.every(word => entry.s.includes(word) || entry.id.includes(word))
, inKeywords = entry => words.every(word => entry.s.includes(word) || entry.id.includes(word) || entry.k.includes(word))

return [
...index.filter(inTitle),
...index.filter(entry => !inTitle(entry) && inKeywords(entry))
].map(entry => entry.id)
}
Loading