import { env } from '../../config/env.js';
import { render as renderMarkdown } from '../public/core/markdown.js';
import { pagePath } from './wiki-seed.js';
/**
* Server-rendered wiki (M17).
*
* The public documentation is delivered as finished HTML rather than assembled
* in the browser. A terms page that needs JavaScript to show its text is a page
* that reads as blank to anything that does not run scripts — a platform
* checking the link before approving an application, a crawler, a reader with
* scripts disabled — and those are exactly the readers it exists for.
*/
const escape = (text) =>
String(text ?? '')
.replaceAll('&', '&')
.replaceAll('<', '<')
.replaceAll('>', '>')
.replaceAll('"', '"');
const document = ({ title, description, body, noindex = false }) => `
${escape(title)}
${body}
`;
/** Sidebar: the page tree and a search box that works without scripts. */
function sidebar(categories, currentSlug, term = '') {
const groups = categories
.map(
(category) => `
`;
/** A page, with its body already turned into HTML. */
export function renderPage(page, categories) {
const { html, headings } = renderMarkdown(page.content);
const updated = new Date(`${page.updated_at}Z`);
const main = `
${escape(page.category)}
${escape(page.title)}
${page.summary ? `
${escape(page.summary)}
` : ''}
${html}
${contents(headings)}
`;
return document({
title: `${page.title} · Documentation FWS`,
description: page.summary || `${page.title} — documentation de l'organisation FWS.`,
body: shell(categories, page.slug, main),
});
}
/** Landing page, and the search results when a term is given. */
export function renderIndex(categories, { term = '', results = null } = {}) {
const list = (pages) =>
pages.length === 0
? '