aboutsummaryrefslogtreecommitdiffhomepage
path: root/nuldoc-src/templates
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2023-03-17 02:27:53 +0900
committernsfisis <nsfisis@gmail.com>2023-03-17 02:27:53 +0900
commitec2ae41b815c4c465a856d800709de6147e5e54f (patch)
treeab05d0e2971cdbcfa55e531e6d977cc552c7adf5 /nuldoc-src/templates
parent29bcdc6c1bad2240d404de9dca2463e46fdc1e93 (diff)
downloadblog.nsfisis.dev-ec2ae41b815c4c465a856d800709de6147e5e54f.tar.gz
blog.nsfisis.dev-ec2ae41b815c4c465a856d800709de6147e5e54f.tar.zst
blog.nsfisis.dev-ec2ae41b815c4c465a856d800709de6147e5e54f.zip
refactor: make Document type class
Diffstat (limited to 'nuldoc-src/templates')
-rw-r--r--nuldoc-src/templates/about.ts19
-rw-r--r--nuldoc-src/templates/post.ts2
-rw-r--r--nuldoc-src/templates/post_list.ts30
-rw-r--r--nuldoc-src/templates/tag.ts28
4 files changed, 39 insertions, 40 deletions
diff --git a/nuldoc-src/templates/about.ts b/nuldoc-src/templates/about.ts
index c41418c..ccd7b1a 100644
--- a/nuldoc-src/templates/about.ts
+++ b/nuldoc-src/templates/about.ts
@@ -110,14 +110,13 @@ export default async function generateAbout(
head,
body,
);
- const doc = {
- root: el("__root__", [], html),
- sourceFilePath: "<about>",
- link: "/about/",
- title: "About",
- summary: "このサイトの著者について",
- tags: [],
- revisions: [],
- };
- return doc;
+ return new Document(
+ el("__root__", [], html),
+ "<about>",
+ "/about/",
+ "About",
+ "このサイトの著者について",
+ [],
+ [],
+ );
}
diff --git a/nuldoc-src/templates/post.ts b/nuldoc-src/templates/post.ts
index c89240c..9a89a73 100644
--- a/nuldoc-src/templates/post.ts
+++ b/nuldoc-src/templates/post.ts
@@ -28,7 +28,7 @@ export default async function convertPost(
metaElement([["name", "author"], ["content", config.blog.author]]),
metaElement([["name", "copyright"], [
"content",
- `&copy; ${doc.revisions[0].date.substring(0, 4)} ${config.blog.author}`,
+ `&copy; ${doc.getCreatedDate().substring(0, 4)} ${config.blog.author}`,
]]),
metaElement([["name", "description"], ["content", doc.summary]]),
];
diff --git a/nuldoc-src/templates/post_list.ts b/nuldoc-src/templates/post_list.ts
index f4a541b..cdd2253 100644
--- a/nuldoc-src/templates/post_list.ts
+++ b/nuldoc-src/templates/post_list.ts
@@ -19,15 +19,15 @@ export default async function convertPostList(
posts: Document[],
config: Config,
): Promise<Document> {
- const doc = {
- root: el("__root__", []),
- sourceFilePath: "<postList>",
- link: "/posts/",
- title: "投稿一覧",
- summary: "投稿した記事の一覧",
- tags: [],
- revisions: [],
- };
+ const doc = new Document(
+ el("__root__", []),
+ "<postList>",
+ "/posts/",
+ "投稿一覧",
+ "投稿した記事の一覧",
+ [],
+ [],
+ );
const head = el(
"head",
@@ -95,8 +95,8 @@ export default async function convertPostList(
),
),
...Array.from(posts).sort((a, b) => {
- const ta = a.revisions[0].date;
- const tb = b.revisions[0].date;
+ const ta = a.getCreatedDate();
+ const tb = b.getCreatedDate();
if (ta > tb) return -1;
if (ta < tb) return 1;
return 0;
@@ -123,16 +123,16 @@ export default async function convertPostList(
text("Posted on"),
el(
"time",
- [["datetime", post.revisions[0].date]],
- text(post.revisions[0].date),
+ [["datetime", post.getCreatedDate()]],
+ text(post.getCreatedDate()),
),
...(post.revisions.length > 1
? [
text(", updated on "),
el("time", [[
"datetime",
- post.revisions[post.revisions.length - 1].date,
- ]], text(post.revisions[post.revisions.length - 1].date)),
+ post.getUpdatedDate(),
+ ]], text(post.getUpdatedDate())),
]
: []),
),
diff --git a/nuldoc-src/templates/tag.ts b/nuldoc-src/templates/tag.ts
index a53e59d..8c296d8 100644
--- a/nuldoc-src/templates/tag.ts
+++ b/nuldoc-src/templates/tag.ts
@@ -22,15 +22,15 @@ export default async function convertTag(
): Promise<Document> {
const tagLabel = (config.blog.tagLabels as { [key: string]: string })[tag];
- const doc = {
- root: el("__root__", []),
- sourceFilePath: `<tag:${tag}>`,
- link: `/tags/${tag}/`,
- title: tagLabel,
- summary: `タグ「${tagLabel}」のついた記事一覧`,
- tags: [],
- revisions: [],
- };
+ const doc = new Document(
+ el("__root__", []),
+ `<tag:${tag}>`,
+ `/tags/${tag}/`,
+ tagLabel,
+ `タグ「${tagLabel}」のついた記事一覧`,
+ [],
+ [],
+ );
const headChildren = [
metaElement([["charset", "UTF-8"]]),
@@ -42,7 +42,7 @@ export default async function convertTag(
metaElement([["name", "copyright"], [
"content",
`&copy; ${
- posts[posts.length - 1].revisions[0].date.substring(0, 4)
+ posts[posts.length - 1].getCreatedDate().substring(0, 4)
} ${config.blog.author}`,
]]),
metaElement([["name", "description"], [
@@ -117,16 +117,16 @@ export default async function convertTag(
text("Posted on"),
el(
"time",
- [["datetime", post.revisions[0].date]],
- text(post.revisions[0].date),
+ [["datetime", post.getCreatedDate()]],
+ text(post.getCreatedDate()),
),
...(post.revisions.length > 1
? [
text(", updated on "),
el("time", [[
"datetime",
- post.revisions[post.revisions.length - 1].date,
- ]], text(post.revisions[post.revisions.length - 1].date)),
+ post.getUpdatedDate(),
+ ]], text(post.getUpdatedDate())),
]
: []),
),