diff options
| author | nsfisis <nsfisis@gmail.com> | 2023-03-18 17:17:11 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2023-03-18 17:17:11 +0900 |
| commit | b98d324fe7eb37e7004926843feede7e636c3301 (patch) | |
| tree | 2a0fe6e6f449eea9cf68022748581862d2b80303 | |
| parent | 0fb528619a4c08e38f3fdd5a8ebbe9c628c236d9 (diff) | |
| download | blog.nsfisis.dev-b98d324fe7eb37e7004926843feede7e636c3301.tar.gz blog.nsfisis.dev-b98d324fe7eb37e7004926843feede7e636c3301.tar.zst blog.nsfisis.dev-b98d324fe7eb37e7004926843feede7e636c3301.zip | |
refactor: move shared codes to templates/utils.ts
| -rw-r--r-- | nuldoc-src/templates/about.ts | 21 | ||||
| -rw-r--r-- | nuldoc-src/templates/post.ts | 20 | ||||
| -rw-r--r-- | nuldoc-src/templates/post_list.ts | 21 | ||||
| -rw-r--r-- | nuldoc-src/templates/tag.ts | 21 | ||||
| -rw-r--r-- | nuldoc-src/templates/utils.ts | 16 |
5 files changed, 44 insertions, 55 deletions
diff --git a/nuldoc-src/templates/about.ts b/nuldoc-src/templates/about.ts index ccd7b1a..2f20aa9 100644 --- a/nuldoc-src/templates/about.ts +++ b/nuldoc-src/templates/about.ts @@ -1,19 +1,12 @@ -import { Element } from "../dom.ts"; import { Document } from "../docbook/document.ts"; import { Config } from "../config.ts"; -import { el, stylesheetLinkElement, text } from "./utils.ts"; - -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); -} +import { + el, + linkElement, + metaElement, + stylesheetLinkElement, + text, +} from "./utils.ts"; export default async function generateAbout( config: Config, diff --git a/nuldoc-src/templates/post.ts b/nuldoc-src/templates/post.ts index 9a89a73..51b9aa9 100644 --- a/nuldoc-src/templates/post.ts +++ b/nuldoc-src/templates/post.ts @@ -1,19 +1,13 @@ import { Element } from "../dom.ts"; import { Document } from "../docbook/document.ts"; import { Config } from "../config.ts"; -import { el, stylesheetLinkElement, text } from "./utils.ts"; - -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); -} +import { + el, + linkElement, + metaElement, + stylesheetLinkElement, + text, +} from "./utils.ts"; export default async function convertPost( doc: Document, diff --git a/nuldoc-src/templates/post_list.ts b/nuldoc-src/templates/post_list.ts index cdd2253..f75b8e1 100644 --- a/nuldoc-src/templates/post_list.ts +++ b/nuldoc-src/templates/post_list.ts @@ -1,19 +1,12 @@ -import { Element } from "../dom.ts"; import { Document } from "../docbook/document.ts"; import { Config } from "../config.ts"; -import { el, stylesheetLinkElement, text } from "./utils.ts"; - -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); -} +import { + el, + linkElement, + metaElement, + stylesheetLinkElement, + text, +} from "./utils.ts"; export default async function convertPostList( posts: Document[], diff --git a/nuldoc-src/templates/tag.ts b/nuldoc-src/templates/tag.ts index 1cbc2c5..8aeac58 100644 --- a/nuldoc-src/templates/tag.ts +++ b/nuldoc-src/templates/tag.ts @@ -1,19 +1,12 @@ -import { Element } from "../dom.ts"; import { Document } from "../docbook/document.ts"; import { Config } from "../config.ts"; -import { el, stylesheetLinkElement, text } from "./utils.ts"; - -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); -} +import { + el, + linkElement, + metaElement, + stylesheetLinkElement, + text, +} from "./utils.ts"; export default async function convertTag( tag: string, diff --git a/nuldoc-src/templates/utils.ts b/nuldoc-src/templates/utils.ts index 65dd506..018c460 100644 --- a/nuldoc-src/templates/utils.ts +++ b/nuldoc-src/templates/utils.ts @@ -33,3 +33,19 @@ export async function stylesheetLinkElement( 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); +} |
