aboutsummaryrefslogtreecommitdiffhomepage
path: root/nuldoc-src/components
diff options
context:
space:
mode:
Diffstat (limited to 'nuldoc-src/components')
-rw-r--r--nuldoc-src/components/global_footer.ts12
-rw-r--r--nuldoc-src/components/global_header.ts37
-rw-r--r--nuldoc-src/components/page_layout.ts89
3 files changed, 138 insertions, 0 deletions
diff --git a/nuldoc-src/components/global_footer.ts b/nuldoc-src/components/global_footer.ts
new file mode 100644
index 0000000..4c9d245
--- /dev/null
+++ b/nuldoc-src/components/global_footer.ts
@@ -0,0 +1,12 @@
+import { Config } from "../config.ts";
+import { el, Element, text } from "../dom.ts";
+
+export function globalFooter(config: Config): Element {
+ return el(
+ "footer",
+ [["class", "footer"]],
+ text(
+ `© ${config.blog.siteCopyrightYear} ${config.blog.author}`,
+ ),
+ );
+}
diff --git a/nuldoc-src/components/global_header.ts b/nuldoc-src/components/global_header.ts
new file mode 100644
index 0000000..4f7df3b
--- /dev/null
+++ b/nuldoc-src/components/global_header.ts
@@ -0,0 +1,37 @@
+import { Config } from "../config.ts";
+import { el, Element, text } from "../dom.ts";
+
+export function globalHeader(config: Config): Element {
+ return el(
+ "header",
+ [["class", "header"]],
+ el(
+ "nav",
+ [["class", "nav"]],
+ el(
+ "ul",
+ [],
+ el(
+ "li",
+ [["class", "logo"]],
+ el("a", [["href", "/"]], text(config.blog.siteName)),
+ ),
+ el(
+ "li",
+ [],
+ el("a", [["href", "/about"]], text("About")),
+ ),
+ el(
+ "li",
+ [],
+ el("a", [["href", "/posts"]], text("Posts")),
+ ),
+ el(
+ "li",
+ [],
+ el("a", [["href", "/slides"]], text("Slides")),
+ ),
+ ),
+ ),
+ );
+}
diff --git a/nuldoc-src/components/page_layout.ts b/nuldoc-src/components/page_layout.ts
new file mode 100644
index 0000000..d76e3b2
--- /dev/null
+++ b/nuldoc-src/components/page_layout.ts
@@ -0,0 +1,89 @@
+import { crypto, toHashString } from "std/crypto/mod.ts";
+import { join } from "std/path/mod.ts";
+import { Config } from "../config.ts";
+import { el, Element, text } from "../dom.ts";
+
+type Params = {
+ metaCopyrightYear: number;
+ metaDescription: string;
+ metaKeywords: string[];
+ metaTitle: string;
+ requiresSyntaxHighlight: boolean;
+};
+
+export async function pageLayout(
+ {
+ metaCopyrightYear,
+ metaDescription,
+ metaKeywords,
+ metaTitle,
+ requiresSyntaxHighlight,
+ }: Params,
+ body: Element,
+ config: Config,
+): Promise<Element> {
+ const head = el(
+ "head",
+ [],
+ metaElement([["charset", "UTF-8"]]),
+ metaElement([["name", "viewport"], [
+ "content",
+ "width=device-width, initial-scale=1.0",
+ ]]),
+ metaElement([["name", "author"], ["content", config.blog.author]]),
+ metaElement([["name", "copyright"], [
+ "content",
+ `&copy; ${metaCopyrightYear} ${config.blog.author}`,
+ ]]),
+ metaElement([["name", "description"], [
+ "content",
+ metaDescription,
+ ]]),
+ ...(metaKeywords.length === 0 ? [] : [
+ metaElement([["name", "keywords"], [
+ "content",
+ metaKeywords.join(","),
+ ]]),
+ ]),
+ linkElement("icon", "/favicon.svg", "image/svg+xml"),
+ el("title", [], text(`${metaTitle} | ${config.blog.siteName}`)),
+ await stylesheetLinkElement("/style.css", config),
+ ...(
+ requiresSyntaxHighlight
+ ? [await stylesheetLinkElement("/hl.css", config)]
+ : []
+ ),
+ );
+ return el(
+ "html",
+ [["lang", "ja-JP"]],
+ head,
+ body,
+ );
+}
+
+async function stylesheetLinkElement(
+ fileName: string,
+ config: Config,
+): Promise<Element> {
+ const filePath = join(Deno.cwd(), config.locations.staticDir, fileName);
+ const content = (await Deno.readFile(filePath)).buffer;
+ const hash = toHashString(await crypto.subtle.digest("MD5", content), "hex");
+ return el("link", [["rel", "stylesheet"], ["href", `${fileName}?h=${hash}`]]);
+}
+
+function metaElement(attrs: [string, string][]): Element {
+ return el("meta", attrs);
+}
+
+function linkElement(
+ rel: string,
+ href: string,
+ type: string | null,
+): Element {
+ const attrs: [string, string][] = [["rel", rel], ["href", href]];
+ if (type !== null) {
+ attrs.push(["type", type]);
+ }
+ return el("link", attrs);
+}