Add support for multilingual legal pages with English aliases, dynamic link replacement in headers, and redirections for alias routes. Update tests, configs, and frontend assets accordingly.

This commit is contained in:
Overlord committed 2026-10-13 16:41:08 +02:00
1 parent 5f3ff481b4
commit 5305687f98
16 files changed
+151 -39

No files matched your search

+22 -1
View File
@@ -1,7 +1,7 @@
import { existsSync, readdirSync, readFileSync } from 'node:fs';
import { readFile } from 'node:fs/promises';
import { extname, join, relative, sep } from 'node:path';
import type { Font } from '@homepage/indexer';
import { escapeHtml, type Font, type LegalPage } from '@homepage/indexer';
export type Asset = {
body: Buffer;
@@ -53,6 +53,27 @@ export function loadAssets(directory: string): Map<string, Asset>
return assets;
}
/**
* Writes the configured legal pages into the header of the terminal page,
* which the frontend build cannot know. Without legal pages the header has no links.
*/
export function setLegalLinks(assets: Map<string, Asset>, legal: LegalPage[]): void
{
const index = assets.get('/index.html');
if (!index) return;
const links = legal.map((page) =>
{
const english = page.aliases[0] ? ` data-en="${escapeHtml(page.aliases[0])}"` : '';
return `<a href="/${escapeHtml(page.route)}"${english}>${escapeHtml(page.route)}</a>`;
});
const html = index.body.toString('utf8').replace(/<nav>[\s\S]*?<\/nav>/, `<nav>${links.join('<span aria-hidden="true">·</span>')}</nav>`);
const asset = { ...index, body: Buffer.from(html) };
assets.set('/index.html', asset);
assets.set('/', asset);
}
const FONT = /^\/assets\/jetbrains-mono-latin-(400|700)-normal-[^/]+\.woff2$/;
/** The Latin JetBrains Mono files of the frontend, so the static pages use the same font. */