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