add inter-work navigation

This commit is contained in:
41666 2023-10-10 12:31:53 -04:00
parent 23d7810ab6
commit dbc1fd7c17
11 changed files with 104 additions and 7 deletions

View file

@ -11,7 +11,18 @@ export const generate = async (works: string[]) => {
.reverse();
for (const work of allWorks) {
const html = `${workTemplate}`.replace(/##name##/g, work);
const workIndex = allWorks.findIndex((w) => w === work);
const previous = allWorks[(workIndex as any) + 1] ?? null;
const next = allWorks[(workIndex as any) - 1] ?? null;
let nav = ``;
if (previous)
nav += `<a class="nav-left" href="/${previous}">⇠ ${previous}</a>`;
if (next) nav += `<a class="nav-right" href="/${next}">${next} ⇢</a>`;
const html = `${workTemplate}`
.replace(/##name##/g, work)
.replace(/##nav##/g, nav);
mkdirSync(`html/${work}`, { recursive: true });
await Bun.write(`html/${work}/index.html`, html);