aboutsummaryrefslogtreecommitdiffhomepage
path: root/nuldoc-src/templates
diff options
context:
space:
mode:
Diffstat (limited to 'nuldoc-src/templates')
-rw-r--r--nuldoc-src/templates/about.ts115
-rw-r--r--nuldoc-src/templates/post.ts174
-rw-r--r--nuldoc-src/templates/post_list.ts153
-rw-r--r--nuldoc-src/templates/tag.ts147
-rw-r--r--nuldoc-src/templates/utils.ts51
5 files changed, 0 insertions, 640 deletions
diff --git a/nuldoc-src/templates/about.ts b/nuldoc-src/templates/about.ts
deleted file mode 100644
index 2f20aa9..0000000
--- a/nuldoc-src/templates/about.ts
+++ /dev/null
@@ -1,115 +0,0 @@
-import { Document } from "../docbook/document.ts";
-import { Config } from "../config.ts";
-import {
- el,
- linkElement,
- metaElement,
- stylesheetLinkElement,
- text,
-} from "./utils.ts";
-
-export default async function generateAbout(
- config: Config,
-): Promise<Document> {
- 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; ${config.blog.siteCopyrightYear} ${config.blog.author}`,
- ]]),
- metaElement([["name", "description"], [
- "content",
- "このサイトの著者について",
- ]]),
- linkElement("icon", "/favicon.svg", "image/svg+xml"),
- el("title", [], text(`About | ${config.blog.siteName}`)),
- await stylesheetLinkElement("/style.css", config),
- );
- const body = el(
- "body",
- [["class", "single"]],
- 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")),
- ),
- ),
- ),
- ),
- el(
- "main",
- [["class", "main"]],
- el(
- "article",
- [["class", "post-single"]],
- el(
- "header",
- [["class", "post-header"]],
- el(
- "h1",
- [["class", "post-title"]],
- text("About"),
- ),
- ),
- el(
- "div",
- [["class", "post-content"]],
- text("WIP"),
- ),
- ),
- ),
- el(
- "footer",
- [["class", "footer"]],
- text(
- `&copy; ${config.blog.siteCopyrightYear} ${config.blog.author}`,
- ),
- ),
- );
- const html = el(
- "html",
- [["lang", "ja-JP"]],
- head,
- body,
- );
- return new Document(
- el("__root__", [], html),
- "<about>",
- "/about/",
- "About",
- "このサイトの著者について",
- [],
- [],
- );
-}
diff --git a/nuldoc-src/templates/post.ts b/nuldoc-src/templates/post.ts
deleted file mode 100644
index 51b9aa9..0000000
--- a/nuldoc-src/templates/post.ts
+++ /dev/null
@@ -1,174 +0,0 @@
-import { Element } from "../dom.ts";
-import { Document } from "../docbook/document.ts";
-import { Config } from "../config.ts";
-import {
- el,
- linkElement,
- metaElement,
- stylesheetLinkElement,
- text,
-} from "./utils.ts";
-
-export default async function convertPost(
- doc: Document,
- config: Config,
-): Promise<Document> {
- const headChildren = [
- 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; ${doc.getCreatedDate().substring(0, 4)} ${config.blog.author}`,
- ]]),
- metaElement([["name", "description"], ["content", doc.summary]]),
- ];
- if (doc.tags.length !== 0) {
- headChildren.push(
- metaElement([["name", "keywords"], [
- "content",
- doc.tags.map((slug) =>
- (config.blog.tagLabels as { [key: string]: string })[slug]
- ).join(","),
- ]]),
- );
- }
- headChildren.push(linkElement("icon", "/favicon.svg", "image/svg+xml"));
- headChildren.push(
- el("title", [], text(`${doc.title} | ${config.blog.siteName}`)),
- );
- headChildren.push(await stylesheetLinkElement("/style.css", config));
- headChildren.push(await stylesheetLinkElement("/hl.css", config));
- const head = el("head", [], ...headChildren);
- const body = el(
- "body",
- [["class", "single"]],
- 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")),
- ),
- ),
- ),
- ),
- el(
- "main",
- [["class", "main"]],
- el(
- "article",
- [["class", "post-single"]],
- el(
- "header",
- [["class", "post-header"]],
- el(
- "h1",
- [["class", "post-title"]],
- text(doc.title),
- ),
- ...(doc.tags.length === 0 ? [] : [
- el(
- "ul",
- [["class", "post-tags"]],
- ...doc.tags.map((slug) =>
- el(
- "li",
- [["class", "tag"]],
- el(
- "a",
- [["href", `/tags/${slug}`]],
- text(
- (config.blog.tagLabels as {
- [key: string]: string;
- })[slug],
- ),
- ),
- )
- ),
- ),
- ]),
- ),
- el(
- "div",
- [["class", "post-content"]],
- el(
- "section",
- [],
- el(
- "h2",
- [["id", "changelog"]],
- text("更新履歴"),
- ),
- el(
- "ol",
- [],
- ...doc.revisions.map((rev) =>
- el(
- "li",
- [["class", "revision"]],
- el(
- "time",
- [["datetime", rev.date]],
- text(rev.date),
- ),
- text(`: ${rev.remark}`),
- )
- ),
- ),
- ),
- // TODO: refactor
- ...(doc.root.children[0] as Element).children,
- // TODO: footnotes
- // <div id="footnotes">
- // <% for footnote in footnotes %>
- // <div class="footnote" id="_footnotedef_<%= footnote.index %>">
- // <a href="#_footnoteref_<%= footnote.index %>"><%= footnote.index %></a>. <%= footnote.text %>
- // </div>
- // <% end %>
- // </div>
- ),
- ),
- ),
- el(
- "footer",
- [["class", "footer"]],
- text(
- `&copy; ${config.blog.siteCopyrightYear} ${config.blog.author}`,
- ),
- ),
- );
- const html = el(
- "html",
- [["lang", "ja-JP"]],
- head,
- body,
- );
- doc.root = el("__root__", [], html);
- return doc;
-}
diff --git a/nuldoc-src/templates/post_list.ts b/nuldoc-src/templates/post_list.ts
deleted file mode 100644
index f75b8e1..0000000
--- a/nuldoc-src/templates/post_list.ts
+++ /dev/null
@@ -1,153 +0,0 @@
-import { Document } from "../docbook/document.ts";
-import { Config } from "../config.ts";
-import {
- el,
- linkElement,
- metaElement,
- stylesheetLinkElement,
- text,
-} from "./utils.ts";
-
-export default async function convertPostList(
- posts: Document[],
- config: Config,
-): Promise<Document> {
- const doc = new Document(
- el("__root__", []),
- "<postList>",
- "/posts/",
- "投稿一覧",
- "投稿した記事の一覧",
- [],
- [],
- );
-
- 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; ${config.blog.siteCopyrightYear} ${config.blog.author}`,
- ]]),
- metaElement([["name", "description"], ["content", doc.summary]]),
- linkElement("icon", "/favicon.svg", "image/svg+xml"),
- el("title", [], text(`${doc.title} | ${config.blog.siteName}`)),
- await stylesheetLinkElement("/style.css", config),
- );
- const body = el(
- "body",
- [["class", "list"]],
- 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")),
- ),
- ),
- ),
- ),
- el(
- "main",
- [["class", "main"]],
- el(
- "header",
- [["class", "page-header"]],
- el(
- "h1",
- [],
- text(doc.title),
- ),
- ),
- ...Array.from(posts).sort((a, b) => {
- const ta = a.getCreatedDate();
- const tb = b.getCreatedDate();
- if (ta > tb) return -1;
- if (ta < tb) return 1;
- return 0;
- }).map((post) =>
- el(
- "article",
- [["class", "post-entry"]],
- el(
- "a",
- [["href", post.link]],
- el(
- "header",
- [["class", "entry-header"]],
- el("h2", [], text(post.title)),
- ),
- el(
- "section",
- [["class", "entry-content"]],
- el("p", [], text(post.summary)),
- ),
- el(
- "footer",
- [["class", "entry-footer"]],
- text("Posted on"),
- el(
- "time",
- [["datetime", post.getCreatedDate()]],
- text(post.getCreatedDate()),
- ),
- ...(post.revisions.length > 1
- ? [
- text(", updated on "),
- el("time", [[
- "datetime",
- post.getUpdatedDate(),
- ]], text(post.getUpdatedDate())),
- ]
- : []),
- ),
- ),
- )
- ),
- ),
- el(
- "footer",
- [["class", "footer"]],
- text(
- `&copy; ${config.blog.siteCopyrightYear} ${config.blog.author}`,
- ),
- ),
- );
- const html = el(
- "html",
- [["lang", "ja-JP"]],
- head,
- body,
- );
-
- doc.root.children = [html];
- return doc;
-}
diff --git a/nuldoc-src/templates/tag.ts b/nuldoc-src/templates/tag.ts
deleted file mode 100644
index 8aeac58..0000000
--- a/nuldoc-src/templates/tag.ts
+++ /dev/null
@@ -1,147 +0,0 @@
-import { Document } from "../docbook/document.ts";
-import { Config } from "../config.ts";
-import {
- el,
- linkElement,
- metaElement,
- stylesheetLinkElement,
- text,
-} from "./utils.ts";
-
-export default async function convertTag(
- tag: string,
- posts: Document[],
- config: Config,
-): Promise<Document> {
- const tagLabel = (config.blog.tagLabels as { [key: string]: string })[tag];
-
- const doc = new Document(
- el("__root__", []),
- `<tag:${tag}>`,
- `/tags/${tag}/`,
- `タグ「${tagLabel}」一覧`,
- `タグ「${tagLabel}」のついた記事一覧`,
- [],
- [],
- );
-
- const headChildren = [
- 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; ${
- posts[posts.length - 1].getCreatedDate().substring(0, 4)
- } ${config.blog.author}`,
- ]]),
- metaElement([["name", "description"], [
- "content",
- doc.summary,
- ]]),
- metaElement([["name", "keywords"], ["content", tagLabel]]),
- linkElement("icon", "/favicon.svg", "image/svg+xml"),
- el("title", [], text(`${doc.title} | ${config.blog.siteName}`)),
- await stylesheetLinkElement("/style.css", config),
- ];
- const head = el("head", [], ...headChildren);
- const body = el(
- "body",
- [["class", "list"]],
- 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")),
- ),
- ),
- ),
- ),
- el(
- "main",
- [["class", "main"]],
- el("header", [["class", "page-header"]], el("h1", [], text(doc.title))),
- ...posts.map((post) =>
- el(
- "article",
- [["class", "post-entry"]],
- el(
- "a",
- [["href", post.link]],
- el(
- "header",
- [["class", "entry-header"]],
- el("h2", [], text(post.title)),
- ),
- el(
- "section",
- [["class", "entry-content"]],
- el("p", [], text(post.summary)),
- ),
- el(
- "footer",
- [["class", "entry-footer"]],
- text("Posted on"),
- el(
- "time",
- [["datetime", post.getCreatedDate()]],
- text(post.getCreatedDate()),
- ),
- ...(post.revisions.length > 1
- ? [
- text(", updated on "),
- el("time", [[
- "datetime",
- post.getUpdatedDate(),
- ]], text(post.getUpdatedDate())),
- ]
- : []),
- ),
- ),
- )
- ),
- ),
- el(
- "footer",
- [["class", "footer"]],
- text(
- `&copy; ${config.blog.siteCopyrightYear} ${config.blog.author}`,
- ),
- ),
- );
- const html = el(
- "html",
- [["lang", "ja-JP"]],
- head,
- body,
- );
-
- doc.root.children = [html];
- return doc;
-}
diff --git a/nuldoc-src/templates/utils.ts b/nuldoc-src/templates/utils.ts
deleted file mode 100644
index 018c460..0000000
--- a/nuldoc-src/templates/utils.ts
+++ /dev/null
@@ -1,51 +0,0 @@
-import { join } from "std/path/mod.ts";
-import { crypto, toHashString } from "std/crypto/mod.ts";
-import { Element, Node, Text } from "../dom.ts";
-import { Config } from "../config.ts";
-
-export function text(content: string): Text {
- return {
- kind: "text",
- content: content,
- raw: false,
- };
-}
-
-export function el(
- name: string,
- attrs: [string, string][],
- ...children: Node[]
-): Element {
- return {
- kind: "element",
- name: name,
- attributes: new Map(attrs),
- children: children,
- };
-}
-
-export 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}`]]);
-}
-
-export function metaElement(attrs: [string, string][]): Element {
- return el("meta", attrs);
-}
-
-export 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);
-}