~ knotless Search/
↑↓ move↵ open⇧↵ all results
0
0

A method named on any docs page links to its entry in the API reference

Merged chadtmiller.com asked to merge into main from chadtmiller.com/group-host:docs-site/method-links
.claude/skills/docs/context.md+6−0
@@ -57,3 +57,9 @@ Design: `README.md` (overview), `spaces.md`, `groups.md`,
`recovery.md`, `moving.md`. Reference: `../reference/api.md`, `mcp.md`,
`cli.md`, `config.md`. `../development.md`. Link to them rather than
restating them.
A method is named in code, never linked by hand: the docs site links it
to its entry in `../reference/api.md`. Its name alone (`addRecoveryKey`)
does when only one method listed there has it; where two share it
(`applyWrites`, `putRecord`, `getRepo`), write it whole
(`com.atproto.space.putRecord`).
docs/development.md+3−1
@@ -101,7 +101,9 @@ repository (`plugins.mjs`). On a reference page, a table of routes or
methods is drawn as a list, each with its HTTP method, and each
`fyi.opensocial` method, or MCP tool, with its lexicon from `lexicons/`
under it, so what it takes and answers cannot drift from the page
(`reference.mjs`). Its look is the console's, from `web/src/tokens.css`.
(`reference.mjs`). A method named in code on any page links to its entry
there, by its whole NSID, or by its name alone where no other method
listed has that name. Its look is the console's, from `web/src/tokens.css`.
`just docs-site` serves it as it changes, at http://localhost:4321/. A
new page goes in the sidebar in `docs-site/astro.config.mjs`.
docs-site/astro.config.mjs+8−1
@@ -12,7 +12,14 @@ const page = (label, slug) => ({ label, slug });
export default defineConfig({
base,
markdown: { processor: unified({ remarkPlugins: [[remarkLinks, { base }], remarkReference] }) },
markdown: {
processor: unified({
remarkPlugins: [
[remarkLinks, { base }],
[remarkReference, { base }]
]
})
},
integrations: [
starlight({
title: 'group-host docs',
docs-site/reference.mjs+46−3
@@ -4,7 +4,9 @@
// badge; and an XRPC method of the host's own has its lexicon under it,
// parameters, input and output, read from lexicons/ so it cannot drift. An
// MCP tool has the lexicon its table's Lexicon column names: the method it
// asks, or the record it writes.
// asks, or the record it writes. Each method there is an anchor, its NSID,
// and a method named in code on any page, `fyi.opensocial.addRecoveryKey` or
// `addRecoveryKey`, links to it.
// docs/ stays plain Markdown: all of this happens as the site is built.
import { existsSync, readdirSync, readFileSync } from 'node:fs';
@@ -25,6 +27,25 @@ const lexicons = new Map(
: []
);
/** Every method the API page lists, by NSID; and by its name alone, where only one has that name. */
const API = join(here, '../docs/reference/api.md');
const listed = existsSync(API)
? new Set(
[
...readFileSync(API, 'utf8').matchAll(
/`(?:GET|POST) ((?:[a-z][a-z0-9-]*\.){2,}[a-zA-Z][a-zA-Z0-9]*)`/g
)
].map((m) => m[1])
)
: new Set();
const short = new Map();
for (const nsid of listed) {
const name = nsid.split('.').pop();
short.set(name, short.has(name) ? null : nsid);
}
/** The NSID a span of code names, if it is a method the API page lists. */
const named = (code) => (listed.has(code) ? code : (short.get(code) ?? undefined));
const METHOD = { query: 'GET', procedure: 'POST', subscription: 'WS' };
const text = (node) =>
@@ -155,6 +176,15 @@ const signature = (code) => ({
/** A cell's code, if the cell starts with some. */
const lead = (cell) => (cell.children[0]?.type === 'inlineCode' ? cell.children[0].value : null);
/** A method's term on the API page is its anchor, its NSID; once on a page, where it is listed twice. */
const anchored = new Set();
function anchor(code) {
const nsid = code.match(/^(?:GET|POST)\s+(\S+)$/)?.[1];
if (!nsid || !listed.has(nsid) || anchored.has(nsid)) return {};
anchored.add(nsid);
return { id: nsid };
}
/** A table of names, each with a sentence or more about it, rather than a grid of values. */
function definitional(table) {
const [, ...rows] = table.children;
@@ -184,7 +214,7 @@ function asList(table) {
const terms = routes
? codes.map(({ code, method }) => ({
type: 'refTerm',
data: { hName: 'dt' },
data: { hName: 'dt', hProperties: anchor(code) },
children: [
...(method ? [badge(method), gap] : []),
signature(code.replace(/^[A-Z]+\s+/, ''))
@@ -245,8 +275,20 @@ function asList(table) {
};
}
export function remarkReference() {
/** A method named in code, outside a link or heading, links to its entry on the API page. */
function linkMethods(node, api) {
if (node.type === 'link' || node.type === 'heading' || node.type === 'refTerm') return;
node.children?.forEach((child, i) => {
const nsid = child.type === 'inlineCode' && named(child.value);
if (nsid) node.children[i] = { type: 'link', url: `${api}#${nsid}`, children: [child] };
else linkMethods(child, api);
});
}
export function remarkReference({ base = '/' } = {}) {
const api = `${base}reference/api/`;
return (tree) => {
anchored.clear();
const visit = (parent) => {
parent.children?.forEach((node, i) => {
if (node.type === 'table' && definitional(node)) parent.children[i] = asList(node);
@@ -283,5 +325,6 @@ export function remarkReference() {
});
};
visit(tree);
linkMethods(tree, api);
};
}