[wip] breadcrumbs
This commit is contained in:
parent
0c99151586
commit
7e45e4ed59
@ -3,7 +3,18 @@ import HighlightPlugin from "@libs/markdown/plugins/highlighting";
|
||||
import { walk } from "@std/fs";
|
||||
import * as pathTools from "@std/path";
|
||||
|
||||
function injectIntoTemplate(name: string, rendered: string): string {
|
||||
function injectIntoTemplate(
|
||||
name: string,
|
||||
rendered: string,
|
||||
dirComponents: [],
|
||||
fileName: string,
|
||||
): string {
|
||||
const breadcrumbs: string[] = [];
|
||||
for (const component of dirComponents) {
|
||||
breadcrumbs.push(`<a>${component}</a>`);
|
||||
}
|
||||
breadcrumbs.push(`<span>${fileName}</span>`);
|
||||
|
||||
let content = [
|
||||
"<!DOCTYPE html>",
|
||||
"<html>",
|
||||
@ -22,6 +33,7 @@ function injectIntoTemplate(name: string, rendered: string): string {
|
||||
"</head>",
|
||||
"<body>",
|
||||
[
|
||||
`<nav>${breadcrumbs.join("/")}</nav>`,
|
||||
rendered,
|
||||
],
|
||||
"</body>",
|
||||
@ -41,8 +53,9 @@ async function renderMarkdown() {
|
||||
const entry of walk("src", { exts: [".md"], includeDirs: false })
|
||||
) {
|
||||
const parsed = pathTools.parse(entry.path);
|
||||
parsed.dir = parsed.dir.replace(/^src[\\/]?/, "");
|
||||
parsed.dir = pathTools.join("-", parsed.dir);
|
||||
const dirComponents = parsed.dir.split(pathTools.SEPARATOR_PATTERN);
|
||||
dirComponents.shift();
|
||||
parsed.dir = pathTools.join("-", ...dirComponents);
|
||||
parsed.ext = ".html";
|
||||
parsed.base = `${parsed.name}${parsed.ext}`;
|
||||
|
||||
@ -50,7 +63,7 @@ async function renderMarkdown() {
|
||||
const content = await renderer.render(await Deno.readTextFile(entry.path));
|
||||
await Deno.writeTextFile(
|
||||
pathTools.format(parsed),
|
||||
injectIntoTemplate(parsed.name, content),
|
||||
injectIntoTemplate(parsed.name, content, dirComponents),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -58,8 +71,9 @@ async function renderMarkdown() {
|
||||
async function copyStaticFiles() {
|
||||
for await (const entry of walk("static", { includeDirs: false })) {
|
||||
const parsed = pathTools.parse(entry.path);
|
||||
parsed.dir = parsed.dir.replace(/^static[\\/]?/, "");
|
||||
parsed.dir = pathTools.join("-", parsed.dir);
|
||||
const dirComponents = parsed.dir.split(pathTools.SEPARATOR_PATTERN);
|
||||
dirComponents.shift();
|
||||
parsed.dir = pathTools.join("-", ...dirComponents);
|
||||
|
||||
await Deno.mkdir(parsed.dir, { recursive: true });
|
||||
await Deno.copyFile(entry.path, pathTools.format(parsed));
|
||||
|
Loading…
x
Reference in New Issue
Block a user