diff options
| author | nsfisis <nsfisis@gmail.com> | 2023-03-19 01:20:16 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2023-03-19 01:30:08 +0900 |
| commit | cb5a2a0afdf822651db035904cd8c1307a7b7743 (patch) | |
| tree | 626ad303be1d53cbcc837d5c5213740a19ac19c4 | |
| parent | ee4f41927c0d83a38b92b99071a64eec01f00413 (diff) | |
| download | blog.nsfisis.dev-cb5a2a0afdf822651db035904cd8c1307a7b7743.tar.gz blog.nsfisis.dev-cb5a2a0afdf822651db035904cd8c1307a7b7743.tar.zst blog.nsfisis.dev-cb5a2a0afdf822651db035904cd8c1307a7b7743.zip | |
refactor: move shared components to components/*
| -rw-r--r-- | nuldoc-src/components/post_page_entry.ts | 47 | ||||
| -rw-r--r-- | nuldoc-src/components/slide_page_entry.ts | 44 | ||||
| -rw-r--r-- | nuldoc-src/pages/post_list.ts | 44 | ||||
| -rw-r--r-- | nuldoc-src/pages/slide_list.ts | 44 | ||||
| -rw-r--r-- | nuldoc-src/pages/tag.ts | 51 |
5 files changed, 101 insertions, 129 deletions
diff --git a/nuldoc-src/components/post_page_entry.ts b/nuldoc-src/components/post_page_entry.ts new file mode 100644 index 0000000..e825dfd --- /dev/null +++ b/nuldoc-src/components/post_page_entry.ts @@ -0,0 +1,47 @@ +import { el, Element, text } from "../dom.ts"; +import { + getPostCreatedDate, + getPostUpdatedDate, + PostPage, +} from "../pages/post.ts"; + +export function postPageEntry(post: PostPage): Element { + return el( + "article", + [["class", "post-entry"]], + el( + "a", + [["href", post.href]], + 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"]], + el( + "time", + [["datetime", getPostCreatedDate(post)]], + text(getPostCreatedDate(post)), + ), + text(" 投稿"), + ...(post.revisions.length > 1 + ? [ + text("、"), + el("time", [[ + "datetime", + getPostUpdatedDate(post), + ]], text(getPostUpdatedDate(post))), + text(" 更新"), + ] + : []), + ), + ), + ); +} diff --git a/nuldoc-src/components/slide_page_entry.ts b/nuldoc-src/components/slide_page_entry.ts new file mode 100644 index 0000000..3aff5ae --- /dev/null +++ b/nuldoc-src/components/slide_page_entry.ts @@ -0,0 +1,44 @@ +import { el, Element, text } from "../dom.ts"; +import { getPostCreatedDate, getPostUpdatedDate } from "../pages/post.ts"; +import { SlidePage } from "../pages/slide.ts"; + +export function slidePageEntry(slide: SlidePage): Element { + return el( + "article", + [["class", "post-entry"]], + el( + "a", + [["href", slide.href]], + el( + "header", + [["class", "entry-header"]], + el("h2", [], text(`登壇: ${slide.event} (${slide.talkType})`)), + ), + el( + "section", + [["class", "entry-content"]], + el("p", [], text(slide.title)), + ), + el( + "footer", + [["class", "entry-footer"]], + el( + "time", + [["datetime", getPostCreatedDate(slide)]], + text(getPostCreatedDate(slide)), + ), + text(" 登壇"), + ...(slide.revisions.length > 1 + ? [ + text("、"), + el("time", [[ + "datetime", + getPostUpdatedDate(slide), + ]], text(getPostUpdatedDate(slide))), + text(" 更新"), + ] + : []), + ), + ), + ); +} diff --git a/nuldoc-src/pages/post_list.ts b/nuldoc-src/pages/post_list.ts index 767b42b..e8f27ee 100644 --- a/nuldoc-src/pages/post_list.ts +++ b/nuldoc-src/pages/post_list.ts @@ -1,10 +1,11 @@ import { globalFooter } from "../components/global_footer.ts"; import { globalHeader } from "../components/global_header.ts"; import { pageLayout } from "../components/page_layout.ts"; +import { postPageEntry } from "../components/post_page_entry.ts"; import { Config } from "../config.ts"; import { el, text } from "../dom.ts"; import { Page } from "../page.ts"; -import { getPostCreatedDate, getPostUpdatedDate, PostPage } from "./post.ts"; +import { getPostCreatedDate, PostPage } from "./post.ts"; export type PostListPage = Page; @@ -36,46 +37,7 @@ export async function generatePostListPage( if (ta > tb) return -1; if (ta < tb) return 1; return 0; - }).map((post) => - el( - "article", - [["class", "post-entry"]], - el( - "a", - [["href", post.href]], - 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"]], - el( - "time", - [["datetime", getPostCreatedDate(post)]], - text(getPostCreatedDate(post)), - ), - text(" 投稿"), - ...(post.revisions.length > 1 - ? [ - text("、"), - el("time", [[ - "datetime", - getPostUpdatedDate(post), - ]], text(getPostUpdatedDate(post))), - text(" 更新"), - ] - : []), - ), - ), - ) - ), + }).map((post) => postPageEntry(post)), ), globalFooter(config), ); diff --git a/nuldoc-src/pages/slide_list.ts b/nuldoc-src/pages/slide_list.ts index 9c375f3..18bea1f 100644 --- a/nuldoc-src/pages/slide_list.ts +++ b/nuldoc-src/pages/slide_list.ts @@ -1,10 +1,11 @@ import { globalFooter } from "../components/global_footer.ts"; import { globalHeader } from "../components/global_header.ts"; import { pageLayout } from "../components/page_layout.ts"; +import { slidePageEntry } from "../components/slide_page_entry.ts"; import { Config } from "../config.ts"; import { el, text } from "../dom.ts"; import { Page } from "../page.ts"; -import { getPostCreatedDate, getPostUpdatedDate } from "./post.ts"; +import { getPostCreatedDate } from "./post.ts"; import { SlidePage } from "./slide.ts"; export type SlideListPage = Page; @@ -37,46 +38,7 @@ export async function generateSlideListPage( if (ta > tb) return -1; if (ta < tb) return 1; return 0; - }).map((slide) => - el( - "article", - [["class", "post-entry"]], - el( - "a", - [["href", slide.href]], - el( - "header", - [["class", "entry-header"]], - el("h2", [], text(`登壇: ${slide.event} (${slide.talkType})`)), - ), - el( - "section", - [["class", "entry-content"]], - el("p", [], text(slide.title)), - ), - el( - "footer", - [["class", "entry-footer"]], - el( - "time", - [["datetime", getPostCreatedDate(slide)]], - text(getPostCreatedDate(slide)), - ), - text(" 登壇"), - ...(slide.revisions.length > 1 - ? [ - text("、"), - el("time", [[ - "datetime", - getPostUpdatedDate(slide), - ]], text(getPostUpdatedDate(slide))), - text(" 更新"), - ] - : []), - ), - ), - ) - ), + }).map((slide) => slidePageEntry(slide)), ), globalFooter(config), ); diff --git a/nuldoc-src/pages/tag.ts b/nuldoc-src/pages/tag.ts index cb518b3..fbab8b1 100644 --- a/nuldoc-src/pages/tag.ts +++ b/nuldoc-src/pages/tag.ts @@ -1,10 +1,12 @@ import { globalFooter } from "../components/global_footer.ts"; import { globalHeader } from "../components/global_header.ts"; import { pageLayout } from "../components/page_layout.ts"; +import { postPageEntry } from "../components/post_page_entry.ts"; +import { slidePageEntry } from "../components/slide_page_entry.ts"; import { Config } from "../config.ts"; import { el, text } from "../dom.ts"; import { Page } from "../page.ts"; -import { getPostCreatedDate, getPostUpdatedDate } from "./post.ts"; +import { getPostCreatedDate } from "./post.ts"; import { TaggedPage } from "./tagged_page.ts"; export interface TagPage extends Page { @@ -30,52 +32,7 @@ export async function generateTagPage( [["class", "main"]], el("header", [["class", "page-header"]], el("h1", [], text(pageTitle))), ...pages.map((page) => - el( - "article", - [["class", "post-entry"]], - el( - "a", - [["href", page.href]], - el( - "header", - [["class", "entry-header"]], - el( - "h2", - [], - text( - "event" in page - ? `登壇: ${page.event} (${page.talkType})` - : page.title, - ), - ), - ), - el( - "section", - [["class", "entry-content"]], - el("p", [], text("event" in page ? page.title : page.summary)), - ), - el( - "footer", - [["class", "entry-footer"]], - el( - "time", - [["datetime", getPostCreatedDate(page)]], - text(getPostCreatedDate(page)), - ), - text("event" in page ? " 登壇" : " 投稿"), - ...(page.revisions.length > 1 - ? [ - text("、"), - el("time", [[ - "datetime", - getPostUpdatedDate(page), - ]], text(getPostUpdatedDate(page))), - text(" 更新"), - ] - : []), - ), - ), - ) + "event" in page ? slidePageEntry(page) : postPageEntry(page) ), ), globalFooter(config), |
