mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2026-11-25 13:11:36 +00:00
feat(docs): add the documentation site
- Astro and Starlight site in docs/ for https://fairrootgroup.github.io/FairMQ/ - 64 pages in eight groups: start, concepts, guides, shared memory, examples, tools, reference and project - API reference and source browser from the Doxygen XML of fairmq/ - Code samples are snippets of the repository files; the build fails when a snippet does not match - Option tables take the names, types and defaults from the code - Interactive diagrams: state machine, zero-copy transfer, region acknowledgements, session objects, topology and channel anatomy - The 404 page sends the URLs of the Doxygen site to the new pages - scripts/check-pages.mjs checks pages, snippets and links without a build; scripts/check-links.mjs checks all links in dist/ Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
33
docs/src/lib/families.mjs
Normal file
33
docs/src/lib/families.mjs
Normal file
@@ -0,0 +1,33 @@
|
||||
// Groups the members of a class by their name, for the filter on the API pages.
|
||||
|
||||
export const FAMILY_ORDER = [
|
||||
'Construction',
|
||||
'Types',
|
||||
'Get',
|
||||
'Set',
|
||||
'Transfer',
|
||||
'Create',
|
||||
'Events',
|
||||
'Other',
|
||||
'Operators',
|
||||
'Constants',
|
||||
'Data',
|
||||
'Friends',
|
||||
];
|
||||
|
||||
export function family(m, owner) {
|
||||
const n = m.name;
|
||||
if (m.kind === 'friend') return 'Friends';
|
||||
if (m.kind === 'typedef' || m.kind === 'enum') return 'Types';
|
||||
if (m.kind === 'variable') return m.static ? 'Constants' : 'Data';
|
||||
if (m.kind === 'function') {
|
||||
if (n === owner.short || n === `~${owner.short}` || /^operator\s*=$/.test(n)) return 'Construction';
|
||||
if (/^operator/.test(n)) return 'Operators';
|
||||
if (/^(Get|Is|Has|Are|Can)[A-Z_]/.test(n)) return 'Get';
|
||||
if (/^(Set|Update|Change|Reset|Add|Remove)[A-Z_]/.test(n)) return 'Set';
|
||||
if (/^(Send|Receive)/.test(n)) return 'Transfer';
|
||||
if (/^(New|Create|Make)[A-Z_]/.test(n)) return 'Create';
|
||||
if (/^(Subscribe|Unsubscribe|On[A-Z])/.test(n)) return 'Events';
|
||||
}
|
||||
return 'Other';
|
||||
}
|
||||
93
docs/src/lib/model.mjs
Normal file
93
docs/src/lib/model.mjs
Normal file
@@ -0,0 +1,93 @@
|
||||
// Shared access to the API model for the generated pages.
|
||||
import { readFileSync } from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { paths, build } from 'virtual:fairmq/data';
|
||||
import { getModel } from '../../scripts/api.mjs';
|
||||
|
||||
export const base = import.meta.env.BASE_URL.replace(/\/$/, '');
|
||||
|
||||
export function model() {
|
||||
return getModel({ xmlDir: paths.xmlDir, repoRoot: paths.repoRoot, base });
|
||||
}
|
||||
|
||||
let theme;
|
||||
export function codeTheme() {
|
||||
theme ??= JSON.parse(readFileSync(path.join(paths.docsDir, 'src/styles/code-theme.json'), 'utf8'));
|
||||
return theme;
|
||||
}
|
||||
|
||||
/** A path without the site base, for Starlight sidebar links (Starlight adds the base). */
|
||||
export const noBase = (href) => (href.startsWith(base + '/') ? href.slice(base.length) : href);
|
||||
|
||||
/** GitHub link to a file and line at the commit of the build. */
|
||||
export function githubUrl(file, line) {
|
||||
const ref = build.commit && build.commit !== 'unknown' ? build.commit : 'dev';
|
||||
return `${build.repo}/blob/${ref}/${file}${line ? `#L${line}` : ''}`;
|
||||
}
|
||||
|
||||
const KIND_LETTER = { class: 'C', struct: 'S', union: 'U', enum: 'E', namespace: 'N' };
|
||||
|
||||
/** Sidebar for the API pages: one group per namespace with its types and enums. */
|
||||
export function apiSidebar() {
|
||||
const m = model();
|
||||
const groups = [];
|
||||
const namespaces = m.namespaces().sort((a, b) => a.name.localeCompare(b.name));
|
||||
for (const ns of namespaces) {
|
||||
const inNs = (t) =>
|
||||
t.name.startsWith(ns.name + '::') &&
|
||||
!namespaces.some((o) => o !== ns && o.name.length > ns.name.length && t.name.startsWith(o.name + '::'));
|
||||
const entries = [
|
||||
...m
|
||||
.types()
|
||||
.filter(inNs)
|
||||
.map((t) => ({ rel: t.name.slice(ns.name.length + 2), link: noBase(t.url), kind: KIND_LETTER[t.kind] })),
|
||||
...ns.visible.filter((e) => e.kind === 'enum').map((e) => ({ rel: e.name, link: noBase(e.page), kind: 'E' })),
|
||||
];
|
||||
// Nested types follow their parent, indented.
|
||||
const key = (rel) => rel.split('::').map((s) => s.toLowerCase());
|
||||
entries.sort((a, b) => {
|
||||
const ka = key(a.rel);
|
||||
const kb = key(b.rel);
|
||||
for (let i = 0; i < Math.min(ka.length, kb.length); i++) if (ka[i] !== kb[i]) return ka[i] < kb[i] ? -1 : 1;
|
||||
return ka.length - kb.length;
|
||||
});
|
||||
const items = entries.map((e) => {
|
||||
const depth = e.rel.split('::').length - 1;
|
||||
return {
|
||||
label: e.rel.split('::').pop(),
|
||||
link: e.link,
|
||||
attrs: { 'data-kind': e.kind, class: depth ? 'fmq-mono fmq-nested' : 'fmq-mono', title: `${ns.name}::${e.rel}` },
|
||||
};
|
||||
});
|
||||
groups.push({
|
||||
label: ns.name,
|
||||
collapsed: ns.name !== 'fair::mq',
|
||||
items: [{ label: 'Namespace overview', link: noBase(ns.url), attrs: { 'data-kind': 'N' } }, ...items],
|
||||
});
|
||||
}
|
||||
return [{ label: 'API reference', link: '/api/' }, ...groups];
|
||||
}
|
||||
|
||||
/** Sidebar for the source pages: one group per directory. */
|
||||
export function sourceSidebar() {
|
||||
const m = model();
|
||||
const dirs = new Map();
|
||||
for (const f of m.sourceFiles) {
|
||||
const dir = path.posix.dirname(f);
|
||||
if (!dirs.has(dir)) dirs.set(dir, []);
|
||||
dirs.get(dir).push({ label: path.posix.basename(f), link: `/source/${f}/`, attrs: { class: 'fmq-mono' } });
|
||||
}
|
||||
return [
|
||||
{ label: 'Source browser', link: '/source/' },
|
||||
...[...dirs].map(([dir, items]) => ({ label: `${dir}/`, collapsed: dir !== 'fairmq', items })),
|
||||
];
|
||||
}
|
||||
|
||||
/** Docs pages that name a file in their `code` front matter. A page that names Foo.cxx also
|
||||
* describes Foo.h, and the other way round. */
|
||||
export function guidesForFile(entries, file) {
|
||||
const stem = (f) => f.replace(/\.(h|cxx)$/, '');
|
||||
return entries
|
||||
.filter((e) => (e.data.code ?? []).some((c) => c === file || stem(c) === stem(file)))
|
||||
.map((e) => ({ label: e.data.title, link: `/${e.id}/` }));
|
||||
}
|
||||
41
docs/src/lib/nav.ts
Normal file
41
docs/src/lib/nav.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
// Sections of the site, for the header and the page titles.
|
||||
|
||||
const labels: Record<string, string> = {
|
||||
start: 'Start',
|
||||
concepts: 'Concepts',
|
||||
guides: 'Guides',
|
||||
shmem: 'Shared memory',
|
||||
tools: 'Tools',
|
||||
reference: 'Reference',
|
||||
examples: 'Examples',
|
||||
project: 'Project',
|
||||
};
|
||||
|
||||
/** The sidebar section of a docs page, from its id (for example "concepts/channels"). */
|
||||
export function sectionLabel(id: string): string | undefined {
|
||||
return labels[id.split('/')[0]];
|
||||
}
|
||||
|
||||
const generated = /^\/(api|source|reference)\//;
|
||||
|
||||
export const sections = [
|
||||
{
|
||||
label: 'Docs',
|
||||
href: '/start/overview/',
|
||||
match: (path: string, base: string) => {
|
||||
const p = path.slice(base.length);
|
||||
return p !== '/' && p !== '' && !generated.test(p);
|
||||
},
|
||||
},
|
||||
{
|
||||
label: 'Reference',
|
||||
href: '/reference/options/',
|
||||
match: (path: string, base: string) => path.startsWith(`${base}/reference/`),
|
||||
},
|
||||
{ label: 'API', href: '/api/', match: (path: string, base: string) => path.startsWith(`${base}/api/`) },
|
||||
{
|
||||
label: 'Source',
|
||||
href: '/source/',
|
||||
match: (path: string, base: string) => path.startsWith(`${base}/source/`),
|
||||
},
|
||||
];
|
||||
Reference in New Issue
Block a user