diff options
Diffstat (limited to 'nuldoc-src')
| -rw-r--r-- | nuldoc-src/commands/build.ts | 5 | ||||
| -rw-r--r-- | nuldoc-src/components/post_page_entry.ts | 9 | ||||
| -rw-r--r-- | nuldoc-src/components/slide_page_entry.ts | 9 | ||||
| -rw-r--r-- | nuldoc-src/docbook/document.ts | 4 | ||||
| -rw-r--r-- | nuldoc-src/pages/about.ts | 3 | ||||
| -rw-r--r-- | nuldoc-src/pages/post.ts | 14 | ||||
| -rw-r--r-- | nuldoc-src/pages/post_list.ts | 5 | ||||
| -rw-r--r-- | nuldoc-src/pages/slide.ts | 10 | ||||
| -rw-r--r-- | nuldoc-src/pages/slide_list.ts | 5 | ||||
| -rw-r--r-- | nuldoc-src/pages/tag.ts | 4 | ||||
| -rw-r--r-- | nuldoc-src/revision.ts | 26 | ||||
| -rw-r--r-- | nuldoc-src/slide/slide.ts | 4 | ||||
| -rw-r--r-- | nuldoc-src/xml.ts | 3 |
13 files changed, 60 insertions, 41 deletions
diff --git a/nuldoc-src/commands/build.ts b/nuldoc-src/commands/build.ts index f4cb013..da7e5ce 100644 --- a/nuldoc-src/commands/build.ts +++ b/nuldoc-src/commands/build.ts @@ -5,6 +5,7 @@ import { Config } from "../config.ts"; import { parseDocBookFile } from "../docbook/parse.ts"; import { Page } from "../page.ts"; import { render } from "../render.ts"; +import { dateToString } from "../revision.ts"; import { generateAboutPage } from "../pages/about.ts"; import { generateHomePage } from "../pages/home.ts"; import { generateNotFoundPage } from "../pages/not_found.ts"; @@ -160,8 +161,8 @@ function collectTags(taggedPages: TaggedPage[]): [string, TaggedPage[]][] { result.push([ tag, tagsAndPages.get(tag).sort((a: TaggedPage, b: TaggedPage) => { - const ta = getPostCreatedDate(a); - const tb = getPostCreatedDate(b); + const ta = dateToString(getPostCreatedDate(a)); + const tb = dateToString(getPostCreatedDate(b)); if (ta > tb) return -1; if (ta < tb) return 1; return 0; diff --git a/nuldoc-src/components/post_page_entry.ts b/nuldoc-src/components/post_page_entry.ts index e825dfd..685c03a 100644 --- a/nuldoc-src/components/post_page_entry.ts +++ b/nuldoc-src/components/post_page_entry.ts @@ -4,6 +4,7 @@ import { getPostUpdatedDate, PostPage, } from "../pages/post.ts"; +import { dateToString } from "../revision.ts"; export function postPageEntry(post: PostPage): Element { return el( @@ -27,8 +28,8 @@ export function postPageEntry(post: PostPage): Element { [["class", "entry-footer"]], el( "time", - [["datetime", getPostCreatedDate(post)]], - text(getPostCreatedDate(post)), + [["datetime", dateToString(getPostCreatedDate(post))]], + text(dateToString(getPostCreatedDate(post))), ), text(" 投稿"), ...(post.revisions.length > 1 @@ -36,8 +37,8 @@ export function postPageEntry(post: PostPage): Element { text("、"), el("time", [[ "datetime", - getPostUpdatedDate(post), - ]], text(getPostUpdatedDate(post))), + dateToString(getPostUpdatedDate(post)), + ]], text(dateToString(getPostUpdatedDate(post)))), text(" 更新"), ] : []), diff --git a/nuldoc-src/components/slide_page_entry.ts b/nuldoc-src/components/slide_page_entry.ts index 3aff5ae..4767ca2 100644 --- a/nuldoc-src/components/slide_page_entry.ts +++ b/nuldoc-src/components/slide_page_entry.ts @@ -1,6 +1,7 @@ import { el, Element, text } from "../dom.ts"; import { getPostCreatedDate, getPostUpdatedDate } from "../pages/post.ts"; import { SlidePage } from "../pages/slide.ts"; +import { dateToString } from "../revision.ts"; export function slidePageEntry(slide: SlidePage): Element { return el( @@ -24,8 +25,8 @@ export function slidePageEntry(slide: SlidePage): Element { [["class", "entry-footer"]], el( "time", - [["datetime", getPostCreatedDate(slide)]], - text(getPostCreatedDate(slide)), + [["datetime", dateToString(getPostCreatedDate(slide))]], + text(dateToString(getPostCreatedDate(slide))), ), text(" 登壇"), ...(slide.revisions.length > 1 @@ -33,8 +34,8 @@ export function slidePageEntry(slide: SlidePage): Element { text("、"), el("time", [[ "datetime", - getPostUpdatedDate(slide), - ]], text(getPostUpdatedDate(slide))), + dateToString(getPostUpdatedDate(slide)), + ]], text(dateToString(getPostUpdatedDate(slide)))), text(" 更新"), ] : []), diff --git a/nuldoc-src/docbook/document.ts b/nuldoc-src/docbook/document.ts index 9f3221b..677c827 100644 --- a/nuldoc-src/docbook/document.ts +++ b/nuldoc-src/docbook/document.ts @@ -1,7 +1,7 @@ import { join } from "std/path/mod.ts"; import { Config } from "../config.ts"; import { DocBookError } from "../errors.ts"; -import { Revision } from "../revision.ts"; +import { Revision, stringToDate } from "../revision.ts"; import { Element, findChildElements, @@ -82,7 +82,7 @@ export function createNewDocumentFromRootElement( } return { number: i + 1, - date: innerText(dateElement).trim(), + date: stringToDate(innerText(dateElement).trim()), remark: innerText(revremarkElement).trim(), }; }, diff --git a/nuldoc-src/pages/about.ts b/nuldoc-src/pages/about.ts index adf4d73..459b88c 100644 --- a/nuldoc-src/pages/about.ts +++ b/nuldoc-src/pages/about.ts @@ -4,6 +4,7 @@ import { pageLayout } from "../components/page_layout.ts"; import { Config } from "../config.ts"; import { el, text } from "../dom.ts"; import { Page } from "../page.ts"; +import { dateToString } from "../revision.ts"; import { getPostCreatedDate } from "./post.ts"; import { SlidePage } from "./slide.ts"; @@ -125,7 +126,7 @@ export async function generateAboutPage( [["href", slide.href]], text( `${ - getPostCreatedDate(slide) + dateToString(getPostCreatedDate(slide)) }: ${slide.event} (${slide.talkType})`, ), ), diff --git a/nuldoc-src/pages/post.ts b/nuldoc-src/pages/post.ts index 0bc313b..d870e99 100644 --- a/nuldoc-src/pages/post.ts +++ b/nuldoc-src/pages/post.ts @@ -6,7 +6,7 @@ import { Config } from "../config.ts"; import { el, Element, text } from "../dom.ts"; import { Document } from "../docbook/document.ts"; import { Page } from "../page.ts"; -import { Revision } from "../revision.ts"; +import { Date, dateToString, Revision } from "../revision.ts"; export interface PostPage extends Page { title: string; @@ -15,11 +15,11 @@ export interface PostPage extends Page { revisions: Revision[]; } -export function getPostCreatedDate(page: { revisions: Revision[] }): string { +export function getPostCreatedDate(page: { revisions: Revision[] }): Date { return page.revisions[0].date; } -export function getPostUpdatedDate(page: { revisions: Revision[] }): string { +export function getPostUpdatedDate(page: { revisions: Revision[] }): Date { return page.revisions[page.revisions.length - 1].date; } @@ -87,8 +87,8 @@ export async function generatePostPage( [["class", "revision"]], el( "time", - [["datetime", rev.date]], - text(rev.date), + [["datetime", dateToString(rev.date)]], + text(dateToString(rev.date)), ), text(`: ${rev.remark}`), ) @@ -113,9 +113,7 @@ export async function generatePostPage( const html = await pageLayout( { - metaCopyrightYear: parseInt( - getPostCreatedDate(doc).substring(0, 4), - ), + metaCopyrightYear: getPostCreatedDate(doc).year, metaDescription: doc.summary, metaKeywords: doc.tags.map((slug) => (config.blog.tagLabels as { [key: string]: string })[slug] diff --git a/nuldoc-src/pages/post_list.ts b/nuldoc-src/pages/post_list.ts index e8f27ee..498b3ef 100644 --- a/nuldoc-src/pages/post_list.ts +++ b/nuldoc-src/pages/post_list.ts @@ -5,6 +5,7 @@ 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 { dateToString } from "../revision.ts"; import { getPostCreatedDate, PostPage } from "./post.ts"; export type PostListPage = Page; @@ -32,8 +33,8 @@ export async function generatePostListPage( ), ), ...Array.from(posts).sort((a, b) => { - const ta = getPostCreatedDate(a); - const tb = getPostCreatedDate(b); + const ta = dateToString(getPostCreatedDate(a)); + const tb = dateToString(getPostCreatedDate(b)); if (ta > tb) return -1; if (ta < tb) return 1; return 0; diff --git a/nuldoc-src/pages/slide.ts b/nuldoc-src/pages/slide.ts index 2b7e202..f2955af 100644 --- a/nuldoc-src/pages/slide.ts +++ b/nuldoc-src/pages/slide.ts @@ -5,7 +5,7 @@ import { pageLayout } from "../components/page_layout.ts"; import { Config } from "../config.ts"; import { el, text } from "../dom.ts"; import { Page } from "../page.ts"; -import { Revision } from "../revision.ts"; +import { dateToString, Revision } from "../revision.ts"; import { Slide } from "../slide/slide.ts"; import { getPostCreatedDate } from "./post.ts"; @@ -82,8 +82,8 @@ export async function generateSlidePage( [["class", "revision"]], el( "time", - [["datetime", rev.date]], - text(rev.date), + [["datetime", dateToString(rev.date)]], + text(dateToString(rev.date)), ), text(`: ${rev.remark}`), ) @@ -119,9 +119,7 @@ export async function generateSlidePage( const html = await pageLayout( { - metaCopyrightYear: parseInt( - getPostCreatedDate(slide).substring(0, 4), - ), + metaCopyrightYear: getPostCreatedDate(slide).year, metaDescription: slide.title, metaKeywords: slide.tags.map((slug) => (config.blog.tagLabels as { [key: string]: string })[slug] diff --git a/nuldoc-src/pages/slide_list.ts b/nuldoc-src/pages/slide_list.ts index 18bea1f..5031436 100644 --- a/nuldoc-src/pages/slide_list.ts +++ b/nuldoc-src/pages/slide_list.ts @@ -5,6 +5,7 @@ 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 { dateToString } from "../revision.ts"; import { getPostCreatedDate } from "./post.ts"; import { SlidePage } from "./slide.ts"; @@ -33,8 +34,8 @@ export async function generateSlideListPage( ), ), ...Array.from(slides).sort((a, b) => { - const ta = getPostCreatedDate(a); - const tb = getPostCreatedDate(b); + const ta = dateToString(getPostCreatedDate(a)); + const tb = dateToString(getPostCreatedDate(b)); if (ta > tb) return -1; if (ta < tb) return 1; return 0; diff --git a/nuldoc-src/pages/tag.ts b/nuldoc-src/pages/tag.ts index fbab8b1..cb60d21 100644 --- a/nuldoc-src/pages/tag.ts +++ b/nuldoc-src/pages/tag.ts @@ -40,9 +40,7 @@ export async function generateTagPage( const html = await pageLayout( { - metaCopyrightYear: parseInt( - getPostCreatedDate(pages[pages.length - 1]).substring(0, 4), - ), + metaCopyrightYear: getPostCreatedDate(pages[pages.length - 1]).year, metaDescription: `タグ「${tagLabel}」のついた記事またはスライドの一覧`, metaKeywords: [tagLabel], metaTitle: `${pageTitle} | ${config.blog.siteName}`, diff --git a/nuldoc-src/revision.ts b/nuldoc-src/revision.ts index 1757694..e04b7ba 100644 --- a/nuldoc-src/revision.ts +++ b/nuldoc-src/revision.ts @@ -1,5 +1,27 @@ +export type Date = { + year: number; + month: number; + day: number; +}; + +export function stringToDate(s: string): Date { + const match = s.match(/(\d{4})-(\d{2})-(\d{2})/); + if (match === null) { + throw new Error(); + } + const [_, y, m, d] = match; + return { year: parseInt(y), month: parseInt(m), day: parseInt(d) }; +} + +export function dateToString(date: Date): string { + const y = `${date.year}`.padStart(4, "0"); + const m = `${date.month}`.padStart(2, "0"); + const d = `${date.day}`.padStart(2, "0"); + return `${y}-${m}-${d}`; +} + export type Revision = { number: number; - date: string; // TODO - remark: string; // TODO: should it be markup text? + date: Date; + remark: string; }; diff --git a/nuldoc-src/slide/slide.ts b/nuldoc-src/slide/slide.ts index 859bd56..a982d4f 100644 --- a/nuldoc-src/slide/slide.ts +++ b/nuldoc-src/slide/slide.ts @@ -1,6 +1,6 @@ import { Config } from "../config.ts"; import { SlideError } from "../errors.ts"; -import { Revision } from "../revision.ts"; +import { Revision, stringToDate } from "../revision.ts"; import { Element, findChildElements, @@ -99,7 +99,7 @@ export function createNewSlideFromRootElement( } return { number: i + 1, - date: innerText(dateElement).trim(), + date: stringToDate(innerText(dateElement).trim()), remark: innerText(revremarkElement).trim(), }; }, diff --git a/nuldoc-src/xml.ts b/nuldoc-src/xml.ts index 9c0ea45..f07161f 100644 --- a/nuldoc-src/xml.ts +++ b/nuldoc-src/xml.ts @@ -1,9 +1,6 @@ import { Element, Node, Text } from "./dom.ts"; import { XmlParseError } from "./errors.ts"; -// TODO -// Support comment? <!-- --> - export async function parseXmlFile(filePath: string): Promise<Element> { const source = await Deno.readTextFile(filePath); return parse({ source: source, index: 0 }); |
