();
const nav: Link[] = [
{ label: 'terminal', href: '/' },
{ label: 'ls', href: '/ls' },
...[...options.legal.keys()].map((route) => ({ label: route, href: `/${route}` })),
];
const html = (title: string, description: string, entryCrumbs: Link[], body: string): SitePage => ({
body: Buffer.from(renderPage({ title, description, crumbs: entryCrumbs, body, nav })),
type: 'text/html; charset=utf-8',
headers: {},
});
for (const entry of index.entries.values())
{
const title = `${entry.path ? `/${entry.path}` : '~'} · security-command.org`;
const route = entry.path ? `/${entry.path}` : '/ls';
if (entry.kind === 'dir')
{
const children = (entry.children ?? []).map((path) => index.entries.get(path)!);
pages.set(route, html(title, describe(entry), crumbs(entry), renderListing(entry, children)));
continue;
}
pages.set(route, html(title, describe(entry), crumbs(entry), renderFile(entry)));
if (entry.content) pages.set(`/raw/${entry.path}`, rawPage(entry as Entry & { content: Buffer }));
}
for (const [routeName, file] of options.legal)
{
const entry = index.entries.get(file);
const body = entry?.kind === 'file'
? renderFile(entry)
: `${escapeHtml(file)} is missing from the content directory.
`;
pages.set(`/${routeName}`, html(`${routeName} · security-command.org`, `${routeName} of security-command.org.`, [], body));
}
const base = options.siteUrl.replace(/\/$/, '');
const urls: [string, Date | undefined][] = [
['/', undefined],
...[...index.entries.values()].map((entry): [string, Date] => [entry.path ? `/${urlPath(entry.path)}` : '/ls', entry.modified]),
...[...options.legal].map(([route, file]): [string, Date | undefined] => [`/${route}`, index.entries.get(file)?.modified]),
];
const sitemap = [
'',
'',
...urls.map(([url, modified]) =>
`${escapeHtml(base + url)}${modified ? `${modified.toISOString().slice(0, 10)}` : ''}`),
'',
'',
].join('\n');
pages.set('/sitemap.xml', { body: Buffer.from(sitemap), type: 'application/xml; charset=utf-8', headers: {} });
const robots = ['User-agent: *', 'Disallow: /ws', 'Disallow: /raw/', `Sitemap: ${base}/sitemap.xml`, ''].join('\n');
pages.set('/robots.txt', { body: Buffer.from(robots), type: 'text/plain; charset=utf-8', headers: {} });
return { pages, hash: index.hash };
}