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:
Claude
2026-11-05 00:17:41 +00:00
committed by Dennis Klein
parent 866f39f54e
commit 992db82b91
120 changed files with 27931 additions and 0 deletions

91
docs/src/pages/404.astro Normal file
View File

@@ -0,0 +1,91 @@
---
// Not found. The old site had Doxygen pages under /FairMQ/latest/ and /FairMQ/v1.x.y/. A script
// sends these URLs to the new API and source pages.
import StarlightPage from '@astrojs/starlight/components/StarlightPage.astro';
import { model, base } from '../lib/model.mjs';
const m = model();
// Doxygen compound id (without the kind prefix) → new URL, without the base.
const types: Record<string, string> = {};
const strip = (u: string) => (u.startsWith(base + '/') ? u.slice(base.length) : u);
for (const t of m.types()) types[t.id.replace(/^(class|struct|union)/, '')] = strip(t.url);
for (const ns of m.namespaces()) types['ns:' + ns.id.replace(/^namespace/, '')] = strip(ns.url);
for (const { e } of m.namespaceEnums()) types[e.qualified.replace(/::/g, '_1_1')] = strip(e.page);
// The built-in devices had the names FairMQBenchmarkSampler, FairMQSink …
for (const d of ['BenchmarkSampler', 'Merger', 'Multiplier', 'Proxy', 'Sink', 'Splitter']) types['FairMQ' + d] = '/tools/builtin-devices/';
// Doxygen file id → source page.
const files: Record<string, string> = {};
for (const f of m.files.values()) if (m.sourceFiles.includes(f.path)) files[f.id] = `/source/${f.path}/`;
const data = JSON.stringify({ t: types, f: files });
---
<StarlightPage frontmatter={{ title: 'Page not found', description: 'This page does not exist.', pagefind: false, editUrl: false, lastUpdated: false, eyebrow: 'Error 404' }}>
<div data-moved hidden>
<p>This page moved. Your browser goes to the new page now.</p>
<p><a data-moved-link href="#">Go to the new page</a></p>
</div>
<div data-missing>
<p>The page does not exist. The documentation has a new structure: the old Doxygen pages are now the <a href={`${base}/api/`}>API reference</a> and the <a href={`${base}/source/`}>source browser</a>.</p>
<p>Use the search at the top of the page, or start from one of these pages:</p>
<ul>
<li><a href={`${base}/`}>Home</a></li>
<li><a href={`${base}/start/overview/`}>Overview</a></li>
<li><a href={`${base}/reference/options/`}>Command-line options</a></li>
<li><a href={`${base}/api/`}>API reference</a></li>
</ul>
</div>
<script type="application/json" id="fmq-moved" set:html={data} />
</StarlightPage>
<script>
// Old URLs: /FairMQ/latest/classfair_1_1mq_1_1Device.html, /FairMQ/v1.4.33/Device_8h_source.html …
const base = import.meta.env.BASE_URL.replace(/\/$/, '');
const { t, f } = JSON.parse(document.getElementById('fmq-moved')!.textContent!);
const target = (() => {
const rel = decodeURIComponent(location.pathname.slice(base.length)).replace(/^\/+/, '');
const m = /^(?:latest|v\d+(?:\.\d+)*)(?:\/(.*))?$/.exec(rel);
if (!m) return null;
const page = (m[1] ?? '').replace(/\.html$/, '');
if (page === '' || page === 'index' || page === 'pages') return '/';
if (/^(annotated|classes|hierarchy|inherits|namespaces|namespacemembers.*|functions.*|graph_legend)$/.test(page)) return '/api/';
if (page === 'files' || page.startsWith('dir_')) return '/source/';
const type = /^(?:class|struct|union)(.+?)(?:-members|__coll__graph|__inherit__graph)?$/.exec(page);
if (type) {
const id = type[1];
if (t[id]) return t[id];
// FairMQDevice → fair::mq::Device, FairMQChannel_1_1… → fair::mq::Channel::…
const legacy = /^FairMQ(.+)$/.exec(id);
if (legacy && t['fair_1_1mq_1_1' + legacy[1]]) return t['fair_1_1mq_1_1' + legacy[1]];
// A nested type that is gone: go to its parent.
const parts = id.split('_1_1');
while (parts.length > 1) {
parts.pop();
const p = parts.join('_1_1');
if (t[p]) return t[p];
}
return '/api/';
}
const ns = /^namespace(.+)$/.exec(page);
if (ns) return t['ns:' + ns[1]] ?? '/api/';
const file = /^(.+?)(?:_source|__incl|__dep__incl)?$/.exec(page)![1];
if (f[file]) return f[file];
// Match by file name if the directory changed: FairMQChannel_8h, ofi_2Context_8h …
const name = file.split('_2').pop()!;
const hit = Object.keys(f).find((k) => k === name || k.endsWith('_2' + name));
if (hit) return f[hit];
const legacy = /^FairMQ(.+)$/.exec(name);
if (legacy) {
const hit2 = Object.keys(f).find((k) => k === legacy[1] || k.endsWith('_2' + legacy[1]));
if (hit2) return f[hit2];
}
return '/source/';
})();
if (target) {
// The anchors of the Doxygen pages do not exist on the new pages.
const url = base + target;
document.querySelector<HTMLElement>('[data-moved]')!.hidden = false;
document.querySelector<HTMLElement>('[data-missing]')!.hidden = true;
document.querySelector<HTMLAnchorElement>('[data-moved-link]')!.href = url;
location.replace(url);
}
</script>

View File

@@ -0,0 +1,365 @@
---
// API pages: one page for each public class, struct, union, namespace and namespace enum.
import StarlightPage from '@astrojs/starlight/components/StarlightPage.astro';
import { getCollection } from 'astro:content';
import Member from '../../components/api/Member.astro';
import CopyButton from '../../components/CopyButton.astro';
import { model, base, apiSidebar, githubUrl, guidesForFile, noBase } from '../../lib/model.mjs';
import { family, FAMILY_ORDER } from '../../lib/families.mjs';
import '../../styles/api.css';
export function getStaticPaths() {
const m = model();
const slug = (url: string) => noBase(url).replace(/^\/api\//, '').replace(/\/$/, '');
return [
...m.types().map((t: any) => ({ params: { slug: slug(t.url) }, props: { kind: 'type', id: t.id } })),
...m.namespaces().map((ns: any) => ({ params: { slug: slug(ns.url) }, props: { kind: 'namespace', id: ns.id } })),
...m.namespaceEnums().map(({ e }: any) => ({ params: { slug: slug(e.page) }, props: { kind: 'enum', id: e.id } })),
];
}
const { kind, id } = Astro.props;
const m = model();
const docs = await getCollection('docs');
const strip = (html: string) => html.replace(/<[^>]+>/g, '').replace(/\s+/g, ' ').trim();
const SECTION_ORDER: [string, string][] = [
['public-type', 'Types'],
['public-func', 'Functions'],
['public-static-func', 'Static functions'],
['public-static-attrib', 'Static data members'],
['public-attrib', 'Data members'],
['protected-type', 'Protected types'],
['protected-func', 'Protected functions'],
['protected-static-func', 'Protected static functions'],
['protected-static-attrib', 'Protected static data members'],
['protected-attrib', 'Protected data members'],
['friend', 'Friends'],
['related', 'Related functions'],
];
const NS_SECTIONS: [string, string][] = [
['typedef', 'Type aliases'],
['func', 'Functions'],
['var', 'Variables'],
];
const slugify = (s: string) => s.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '');
let page: any;
if (kind === 'type') {
const rec = m.compounds.get(id);
const sections = SECTION_ORDER.map(([key, label]) => ({
id: slugify(label),
label,
members: rec.visible.filter((x: any) => x.section === key),
})).filter((s) => s.members.length > 0);
const known = new Set(SECTION_ORDER.map(([k]) => k));
const otherMembers = rec.visible.filter((x: any) => !known.has(x.section));
if (otherMembers.length) sections.push({ id: 'other-members', label: 'Other members', members: otherMembers });
const nested = rec.inner.map((i: string) => m.compounds.get(i)).filter((c: any) => c && c.public);
const headings: any[] = [];
if (nested.length) headings.push({ depth: 2, slug: 'nested-types', text: 'Nested types' });
for (const s of sections) {
headings.push({ depth: 2, slug: s.id, text: s.label });
for (const x of s.members) if (x.overload === 1) headings.push({ depth: 3, slug: x.anchor, text: x.name });
}
const families = new Map<string, number>();
for (const x of rec.visible) {
const f = family(x, rec);
families.set(f, (families.get(f) ?? 0) + 1);
}
page = {
rec,
title: rec.short,
titleKind: rec.templ ? `${rec.kind} template` : rec.kind,
eyebrow: `API · ${rec.scope}`,
searchTitle: rec.name,
file: rec.file,
line: rec.line,
include: rec.include,
sections,
nested,
headings,
families: FAMILY_ORDER.filter((f) => families.has(f)).map((f) => [f, families.get(f)]),
total: rec.visible.length,
};
} else if (kind === 'namespace') {
const rec = m.compounds.get(id);
const types = m
.types()
.filter((t: any) => t.scope === rec.name)
.sort((a: any, b: any) => a.short.localeCompare(b.short, 'en', { sensitivity: 'base' }));
const enums = rec.visible.filter((x: any) => x.kind === 'enum');
const sections = NS_SECTIONS.map(([key, label]) => ({
id: slugify(label),
label,
members: rec.visible.filter((x: any) => x.section === key && x.kind !== 'enum'),
})).filter((s) => s.members.length > 0);
const subs = rec.innerNamespaces.map((i: string) => m.compounds.get(i)).filter((c: any) => c && c.public);
const headings: any[] = [];
if (subs.length) headings.push({ depth: 2, slug: 'namespaces', text: 'Namespaces' });
if (types.length) headings.push({ depth: 2, slug: 'types', text: 'Classes and structs' });
if (enums.length) headings.push({ depth: 2, slug: 'enums', text: 'Enums' });
for (const s of sections) {
headings.push({ depth: 2, slug: s.id, text: s.label });
for (const x of s.members) if (x.overload === 1) headings.push({ depth: 3, slug: x.anchor, text: x.name });
}
page = { rec, title: rec.name, titleKind: 'namespace', eyebrow: 'API', searchTitle: rec.name, types, enums, sections, subs, headings };
} else {
const e = m.members.get(id);
const ns = m.compounds.get(e.owner);
page = {
e,
ns,
title: e.name,
titleKind: e.strong ? 'enum class' : 'enum',
eyebrow: `API · ${ns.name}`,
searchTitle: e.qualified,
file: e.file,
line: e.line,
include: m.publicHeaders.has(e.file) ? e.file : null,
headings: [{ depth: 2, slug: 'values', text: 'Values' }],
};
}
const descRec = page.rec ?? page.e;
const description = strip(descRec.brief || '') || `${page.titleKind} ${page.searchTitle}`;
const guides = page.file ? guidesForFile(docs, page.file) : [];
const srcHref = page.file ? `${base}/source/${page.file}/#L${page.line}` : null;
---
<StarlightPage
frontmatter={{
title: page.title,
description,
eyebrow: page.eyebrow,
titleKind: page.titleKind,
searchTitle: page.searchTitle,
code: page.file ? [page.file] : [],
guides,
tableOfContents: { minHeadingLevel: 2, maxHeadingLevel: 3 },
}}
sidebar={apiSidebar()}
headings={page.headings}
>
{
page.file && (
<div class="api-meta">
{page.include && (
<span class="api-inc">
<code>#include &lt;{page.include}&gt;</code>
<CopyButton text={`#include <${page.include}>`} label="Copy the include line" />
</span>
)}
<a href={srcHref}>
{page.file}:{page.line}
</a>
<a href={githubUrl(page.file, page.line)}>GitHub ↗</a>
</div>
)
}
{
kind === 'type' && (
<>
{page.rec.templ && (
<pre class="mem-sig api-templ">
<code set:html={`${page.rec.templ}\n<span class="k">${page.rec.kind}</span> <b>${page.rec.short}</b>`} />
</pre>
)}
{(page.rec.bases.length > 0 || page.rec.derived.length > 0) && (
<dl class="api-rel">
{page.rec.bases.length > 0 && (
<>
<dt>Inherits from</dt>
<dd set:html={page.rec.bases.map((b: any) => `<code>${b.html}</code>`).join(', ')} />
</>
)}
{page.rec.derived.length > 0 && (
<>
<dt>Inherited by</dt>
<dd set:html={page.rec.derived.map((b: any) => `<code>${b.html}</code>`).join(', ')} />
</>
)}
</dl>
)}
{page.rec.brief && <p class="api-lead" set:html={page.rec.brief} />}
{page.rec.detail && <div class="api-detail" set:html={page.rec.detail} />}
{!page.rec.documented && <p class="mem-none">No comment in the header yet.</p>}
{page.nested.length > 0 && (
<>
<h2 id="nested-types">Nested types</h2>
<ul class="api-list">
{page.nested.map((c: any) => (
<li>
<a href={c.url}>
<code>{c.short}</code>
</a>
<span class="fmq-badge">{c.kind}</span>
{c.brief && <span class="api-list-brief" set:html={c.brief} />}
</li>
))}
</ul>
</>
)}
{page.total > 10 && (
<div class="api-filter" data-api-filter role="group" aria-label="Filter members">
<input type="search" placeholder="Filter members" aria-label="Filter members by name" />
<div class="api-chips">
<button type="button" aria-pressed="true" data-f="">
All <b>{page.total}</b>
</button>
{page.families.map(([f, n]: any) => (
<button type="button" aria-pressed="false" data-f={f}>
{f} <b>{n}</b>
</button>
))}
</div>
<p class="api-count" aria-live="polite" />
</div>
)}
{page.sections.map((s: any) => (
<section class="api-sec" data-sec>
<h2 id={s.id}>{s.label}</h2>
{s.members.map((x: any) => (
<Member m={x} owner={page.rec} />
))}
</section>
))}
</>
)
}
{
kind === 'namespace' && (
<>
{page.rec.brief && <p class="api-lead" set:html={page.rec.brief} />}
{page.rec.detail && <div class="api-detail" set:html={page.rec.detail} />}
{page.subs.length > 0 && (
<>
<h2 id="namespaces">Namespaces</h2>
<ul class="api-list">
{page.subs.map((c: any) => (
<li>
<a href={c.url}>
<code>{c.name}</code>
</a>
</li>
))}
</ul>
</>
)}
{page.types.length > 0 && (
<>
<h2 id="types">Classes and structs</h2>
<ul class="api-list">
{page.types.map((c: any) => (
<li>
<a href={c.url}>
<code>{c.short}</code>
</a>
<span class="fmq-badge">{c.kind}</span>
{c.brief && <span class="api-list-brief" set:html={c.brief} />}
</li>
))}
</ul>
</>
)}
{page.enums.length > 0 && (
<>
<h2 id="enums">Enums</h2>
<ul class="api-list">
{page.enums.map((e: any) => (
<li>
<a href={e.page}>
<code>{e.name}</code>
</a>
<span class="fmq-badge">{e.strong ? 'enum class' : 'enum'}</span>
{e.brief && <span class="api-list-brief" set:html={e.brief} />}
</li>
))}
</ul>
</>
)}
{page.sections.map((s: any) => (
<section class="api-sec">
<h2 id={s.id}>{s.label}</h2>
{s.members.map((x: any) => (
<Member m={x} />
))}
</section>
))}
</>
)
}
{
kind === 'enum' && (
<>
<pre class="mem-sig">
<code set:html={page.e.sigHtml} />
</pre>
{page.e.brief && <p class="api-lead" set:html={page.e.brief} />}
{page.e.detail && <div class="api-detail" set:html={page.e.detail} />}
<h2 id="values">Values</h2>
<div class="doc-table">
<table class="enum-values">
<thead>
<tr>
<th>Enumerator</th>
<th>Value</th>
<th>Description</th>
</tr>
</thead>
<tbody>
{page.e.values.map((v: any) => (
<tr id={v.anchor}>
<td>
<code>{v.name}</code>
</td>
<td>{v.init ? <code>{v.init}</code> : <span class="muted">—</span>}</td>
<td set:html={v.html || '<span class="muted">—</span>'} />
</tr>
))}
</tbody>
</table>
</div>
</>
)
}
</StarlightPage>
<script>
// Member filter: by name family and by text.
for (const root of document.querySelectorAll<HTMLElement>('[data-api-filter]')) {
const input = root.querySelector('input')!;
const chips = [...root.querySelectorAll<HTMLButtonElement>('button[data-f]')];
const count = root.querySelector('.api-count')!;
const mems = [...document.querySelectorAll<HTMLElement>('.mem')];
let fam = '';
const apply = () => {
const q = input.value.trim().toLowerCase();
let shown = 0;
for (const el of mems) {
const ok = (!fam || el.dataset.family === fam) && (!q || (el.dataset.name ?? '').includes(q));
el.hidden = !ok;
if (ok) shown++;
}
for (const sec of document.querySelectorAll<HTMLElement>('[data-sec]')) {
sec.hidden = !sec.querySelector('.mem:not([hidden])');
}
count.textContent = fam || q ? `${shown} of ${mems.length} members` : '';
};
input.addEventListener('input', apply);
for (const c of chips) {
c.addEventListener('click', () => {
fam = c.dataset.f ?? '';
for (const o of chips) o.setAttribute('aria-pressed', String(o === c));
apply();
});
}
}
</script>

View File

@@ -0,0 +1,64 @@
---
// API overview: the public namespaces with their types and enums.
import StarlightPage from '@astrojs/starlight/components/StarlightPage.astro';
import { model, base, apiSidebar } from '../../lib/model.mjs';
import '../../styles/api.css';
const m = model();
const namespaces = m.namespaces().sort((a: any, b: any) => a.name.localeCompare(b.name));
const groups = namespaces
.map((ns: any) => ({
ns,
id: ns.name.replace(/::/g, '-'),
types: m
.types()
.filter((t: any) => t.scope === ns.name)
.sort((a: any, b: any) => a.short.localeCompare(b.short, 'en', { sensitivity: 'base' })),
enums: ns.visible.filter((x: any) => x.kind === 'enum'),
}))
.filter((g: any) => g.types.length || g.enums.length);
const count = m.types().length;
---
<StarlightPage
frontmatter={{
title: 'API reference',
description: 'The public classes, structs, enums and functions of FairMQ, generated from the installed headers.',
tableOfContents: { minHeadingLevel: 2, maxHeadingLevel: 2 },
}}
sidebar={apiSidebar()}
headings={groups.map((g: any) => ({ depth: 2, slug: g.id, text: g.ns.name }))}
>
<p class="api-lead">
These pages show the {count} public types of FairMQ and their members. Doxygen reads the installed headers at each
build of this site, so the signatures are always current. The text comes from the comments in the headers.
</p>
<p>
Each member links to its line in the <a href={`${base}/source/`}>source browser</a>. Use the search (<kbd>Ctrl</kbd> <kbd>K</kbd>)
to find a class or a member by name.
</p>
{
groups.map((g: any) => (
<>
<h2 id={g.id}>
<a href={g.ns.url}>
<code>{g.ns.name}</code>
</a>
</h2>
<ul class="api-list">
{[...g.types, ...g.enums.map((e: any) => ({ ...e, short: e.name, url: e.page, kind: e.strong ? 'enum class' : 'enum' }))]
.sort((a: any, b: any) => a.short.localeCompare(b.short, 'en', { sensitivity: 'base' }))
.map((c: any) => (
<li>
<a href={c.url}>
<code>{c.short}</code>
</a>
<span class="fmq-badge">{c.kind}</span>
{c.brief ? <span class="api-list-brief" set:html={c.brief} /> : <span class="api-list-brief muted">No comment yet.</span>}
</li>
))}
</ul>
</>
))
}
</StarlightPage>

View File

@@ -0,0 +1,142 @@
---
// Source browser: one page for each C++ file in fairmq/.
import StarlightPage from '@astrojs/starlight/components/StarlightPage.astro';
import { getCollection } from 'astro:content';
import { paths } from 'virtual:fairmq/data';
import { model, base, codeTheme, sourceSidebar, githubUrl, guidesForFile } from '../../lib/model.mjs';
import { renderSourceFile } from '../../../scripts/source.mjs';
import '../../styles/source.css';
export function getStaticPaths() {
return model().sourceFiles.map((f: string) => ({ params: { path: f } }));
}
const file = Astro.params.path as string;
const m = model();
const out = await renderSourceFile(m, file, { theme: codeTheme(), repoRoot: paths.repoRoot });
const fileRec = m.files.get(file);
const defined = (fileRec?.defines ?? []).filter((c: any) => c.public);
const isPublic = m.publicHeaders.has(file);
const docs = await getCollection('docs');
const guides = guidesForFile(docs, file);
const name = file.split('/').pop();
---
<StarlightPage
frontmatter={{
title: name,
description: `Source of ${file} in FairMQ.`,
eyebrow: `Source · ${file.split('/').slice(0, -1).join('/')}/`,
titleKind: file.endsWith('.h') ? (isPublic ? 'public header' : 'header') : 'source',
searchTitle: file,
tableOfContents: false,
guides,
}}
sidebar={sourceSidebar()}
headings={[]}
>
{
defined.length > 0 && (
<p class="src-defines">
Defines {defined.map((c: any) => `${c.kind} ${c.name}`).join(', ')}.
</p>
)
}
{
guides.length > 0 && (
<p class="src-guides">
Described in{' '}
{guides.map((g: any, i: number) => (
<>
{i > 0 && ', '}
<a href={`${base}${g.link}`}>{g.label}</a>
</>
))}
.
</p>
)
}
<div class="src-head not-content">
<span class="src-path">{file}</span>
<span class="src-info">{out.lines} lines · C++</span>
<span class="src-acts">
{
defined.map((c: any) => (
<a class="fmq-badge mark" href={c.url}>
API: {c.short}
</a>
))
}
<a class="fmq-badge" href={githubUrl(file)}>GitHub ↗</a>
</span>
</div>
<div class="src-code not-content" data-pagefind-ignore>
<pre><code set:html={out.html} /></pre>
<div class="src-card" role="tooltip" hidden></div>
</div>
<script type="application/json" id="src-symbols" set:html={JSON.stringify(out.symbols).replace(/</g, '\\u003c')} />
</StarlightPage>
<script>
// Line marks from the URL (#L10 or #L10-L20), shift-click to mark a range,
// and a card with the symbol on hover or focus.
const code = document.querySelector<HTMLElement>('.src-code');
if (code) {
const rows = () => code.querySelectorAll<HTMLElement>('.row.hl');
const mark = () => {
rows().forEach((r) => r.classList.remove('hl'));
const m = /^#L(\d+)(?:-L(\d+))?$/.exec(location.hash);
if (!m) return;
const a = Number(m[1]);
const b = Number(m[2] ?? m[1]);
for (let i = Math.min(a, b); i <= Math.max(a, b); i++) document.getElementById(`L${i}`)?.classList.add('hl');
};
mark();
addEventListener('hashchange', mark);
code.addEventListener('click', (e) => {
const ln = (e.target as HTMLElement).closest<HTMLAnchorElement>('a.ln');
if (!ln || !e.shiftKey) return;
const cur = /^#L(\d+)/.exec(location.hash);
if (!cur) return;
e.preventDefault();
const to = ln.getAttribute('href')!.slice(2);
history.replaceState(null, '', `#L${cur[1]}-L${to}`);
mark();
});
const symbols = JSON.parse(document.getElementById('src-symbols')?.textContent ?? '[]');
const card = code.querySelector<HTMLElement>('.src-card')!;
let timer: number | undefined;
const esc = (s: string) => s.replace(/[&<>"]/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' })[c]!);
const show = (a: HTMLElement) => {
const s = symbols[Number(a.dataset.s)];
if (!s) return;
clearTimeout(timer);
card.innerHTML = `<span class="k">${esc(s.k)}</span><b>${esc(s.n)}</b>${s.s && s.s !== s.n ? `<code>${esc(s.s)}</code>` : ''}<span class="l">${esc(s.l)}</span>`;
card.hidden = false;
const box = code.getBoundingClientRect();
const r = a.getBoundingClientRect();
const left = Math.max(8, Math.min(r.left - box.left, box.width - card.offsetWidth - 8));
card.style.left = `${left}px`;
card.style.top = `${r.bottom - box.top + code.scrollTop + 6}px`;
};
const hide = () => {
timer = window.setTimeout(() => (card.hidden = true), 120);
};
code.addEventListener('pointerover', (e) => {
const a = (e.target as HTMLElement).closest<HTMLElement>('a.sym');
if (a) show(a);
});
code.addEventListener('pointerout', (e) => {
if ((e.target as HTMLElement).closest('a.sym')) hide();
});
code.addEventListener('focusin', (e) => {
const a = (e.target as HTMLElement).closest<HTMLElement>('a.sym');
if (a) show(a);
});
code.addEventListener('focusout', hide);
addEventListener('keydown', (e) => {
if (e.key === 'Escape') card.hidden = true;
});
}
</script>

View File

@@ -0,0 +1,67 @@
---
// Source browser overview: all C++ files in fairmq/, by directory.
import StarlightPage from '@astrojs/starlight/components/StarlightPage.astro';
import { readFileSync } from 'node:fs';
import path from 'node:path';
import { paths } from 'virtual:fairmq/data';
import { model, base, sourceSidebar } from '../../lib/model.mjs';
import '../../styles/source.css';
const m = model();
const dirs = new Map<string, any[]>();
let total = 0;
for (const f of m.sourceFiles) {
const dir = path.posix.dirname(f);
const lines = readFileSync(path.join(paths.repoRoot, f), 'utf8').replace(/\n$/, '').split('\n').length;
total += lines;
const defined = (m.files.get(f)?.defines ?? []).filter((c: any) => c.public);
if (!dirs.has(dir)) dirs.set(dir, []);
dirs.get(dir)!.push({ f, name: path.posix.basename(f), lines, defined, pub: m.publicHeaders.has(f) });
}
const id = (d: string) => d.replace(/\//g, '-');
---
<StarlightPage
frontmatter={{
title: 'Source browser',
description: 'All C++ files of the FairMQ library, with line anchors and links to the API pages.',
tableOfContents: { minHeadingLevel: 2, maxHeadingLevel: 2 },
}}
sidebar={sourceSidebar()}
headings={[...dirs.keys()].map((d) => ({ depth: 2, slug: id(d), text: `${d}/` }))}
>
<p class="api-lead">
Every C++ file of <code>fairmq/</code> as a page: {m.sourceFiles.length} files with {total.toLocaleString('en')} lines.
Doxygen finds the symbols. A symbol links to its API page, or to the line where it is defined.
</p>
<p>
Each line has an anchor, for example <a href={`${base}/source/fairmq/Channel.h/#L36`}><code>Channel.h/#L36</code></a>. Shift-click a
second line number to mark a range. A <span class="fmq-badge mark">public</span> header is installed with FairMQ.
</p>
{
[...dirs].map(([dir, list]) => (
<>
<h2 id={id(dir)}>
<code>{dir}/</code>
</h2>
<ul class="src-list">
{list.map((x) => (
<li>
<a href={`${base}/source/${x.f}/`}>
<code>{x.name}</code>
</a>
<span class="src-lines">{x.lines}</span>
<span class="src-meta">
{x.pub && <span class="fmq-badge mark">public</span>}
{x.defined.slice(0, 4).map((c: any) => (
<a href={c.url}>{c.short}</a>
))}
{x.defined.length > 4 && <span class="muted">+{x.defined.length - 4}</span>}
</span>
</li>
))}
</ul>
</>
))
}
</StarlightPage>