diff options
| -rw-r--r-- | vhosts/blog/nuldoc-src/atom/types.ts | 19 | ||||
| -rw-r--r-- | vhosts/blog/nuldoc-src/commands/build.ts | 10 | ||||
| -rw-r--r-- | vhosts/blog/nuldoc-src/generators/atom.ts (renamed from vhosts/blog/nuldoc-src/atom/generate.ts) | 56 | ||||
| -rw-r--r-- | vhosts/blog/nuldoc-src/jsx/types.d.ts | 11 | ||||
| -rw-r--r-- | vhosts/blog/nuldoc-src/pages/AtomPage.tsx | 26 |
5 files changed, 67 insertions, 55 deletions
diff --git a/vhosts/blog/nuldoc-src/atom/types.ts b/vhosts/blog/nuldoc-src/atom/types.ts deleted file mode 100644 index 66fde5ba..00000000 --- a/vhosts/blog/nuldoc-src/atom/types.ts +++ /dev/null @@ -1,19 +0,0 @@ -export type Feed = { - author: string; - icon: string; - id: string; - linkToSelf: string; - linkToAlternate: string; - title: string; - updated: string; - entries: Entry[]; -}; - -export type Entry = { - id: string; - linkToAlternate: string; - published: string; - summary: string; - title: string; - updated: string; -}; diff --git a/vhosts/blog/nuldoc-src/commands/build.ts b/vhosts/blog/nuldoc-src/commands/build.ts index a596dc2a..0c066b40 100644 --- a/vhosts/blog/nuldoc-src/commands/build.ts +++ b/vhosts/blog/nuldoc-src/commands/build.ts @@ -1,7 +1,7 @@ import { dirname, join, joinGlobs } from "std/path/mod.ts"; import { ensureDir } from "std/fs/mod.ts"; import { expandGlob } from "std/fs/expand_glob.ts"; -import { generateFeedPageFromEntries } from "../atom/generate.ts"; +import { generateFeedPageFromEntries } from "../generators/atom.ts"; import { Config, getTagLabel } from "../config.ts"; import { parseNulDocFile } from "../ndoc/parse.ts"; import { Page } from "../page.ts"; @@ -73,7 +73,7 @@ async function parsePosts( async function buildPostListPage(posts: PostPage[], config: Config) { const postListPage = await generatePostListPage(posts, config); await writePage(postListPage, config); - const postFeedPage = generateFeedPageFromEntries( + const postFeedPage = await generateFeedPageFromEntries( postListPage.href, "posts", `投稿一覧|${config.blog.siteName}`, @@ -118,7 +118,7 @@ async function parseSlides( async function buildSlideListPage(slides: SlidePage[], config: Config) { const slideListPage = await generateSlideListPage(slides, config); await writePage(slideListPage, config); - const slideFeedPage = generateFeedPageFromEntries( + const slideFeedPage = await generateFeedPageFromEntries( slideListPage.href, "slides", `スライド一覧|${config.blog.siteName}`, @@ -148,7 +148,7 @@ async function buildFeedOfAllContents( slides: SlidePage[], config: Config, ) { - const feed = generateFeedPageFromEntries( + const feed = await generateFeedPageFromEntries( "/", "all", config.blog.siteName, @@ -168,7 +168,7 @@ async function buildTagPages( for (const [tag, pages] of tagsAndPages) { const tagPage = await generateTagPage(tag, pages, config); await writePage(tagPage, config); - const tagFeedPage = generateFeedPageFromEntries( + const tagFeedPage = await generateFeedPageFromEntries( tagPage.href, `tag-${tag}`, `タグ「${getTagLabel(config, tag)}」一覧|${config.blog.siteName}`, diff --git a/vhosts/blog/nuldoc-src/atom/generate.ts b/vhosts/blog/nuldoc-src/generators/atom.ts index 3c76f6c5..6ad07b46 100644 --- a/vhosts/blog/nuldoc-src/atom/generate.ts +++ b/vhosts/blog/nuldoc-src/generators/atom.ts @@ -1,20 +1,40 @@ import { Config } from "../config.ts"; -import { el } from "../dom.ts"; import { Page } from "../page.ts"; -import { Entry, Feed } from "./types.ts"; import { PostPage } from "../generators/post.ts"; import { SlidePage } from "../generators/slide.ts"; import { dateToRfc3339String } from "../revision.ts"; +import AtomPage from "../pages/AtomPage.tsx"; +import { renderToDOM } from "../jsx/render.ts"; + +export type Feed = { + author: string; + icon: string; + id: string; + linkToSelf: string; + linkToAlternate: string; + title: string; + updated: string; + entries: Entry[]; +}; + +export type Entry = { + id: string; + linkToAlternate: string; + published: string; + summary: string; + title: string; + updated: string; +}; const BASE_NAME = "atom.xml"; -export function generateFeedPageFromEntries( +export async function generateFeedPageFromEntries( alternateLink: string, feedSlug: string, feedTitle: string, entries: Array<PostPage | SlidePage>, config: Config, -): Page { +): Promise<Page> { const entries_: Entry[] = []; for (const entry of entries) { entries_.push({ @@ -51,35 +71,9 @@ export function generateFeedPageFromEntries( }; return { - root: buildXmlTree(feed), + root: await renderToDOM(AtomPage({ feed: feed })), renderer: "xml", destFilePath: feedPath, href: feedPath, }; } - -function buildXmlTree(feed: Feed) { - return el( - "feed", - { xmlns: "http://www.w3.org/2005/Atom" }, - el("id", {}, feed.id), - el("title", {}, feed.title), - el("link", { rel: "alternate", href: feed.linkToAlternate }), - el("link", { rel: "self", href: feed.linkToSelf }), - el("author", {}, el("name", {}, feed.author)), - el("updated", {}, feed.updated), - ...feed.entries.map( - (entry) => - el( - "entry", - {}, - el("id", {}, entry.id), - el("link", { rel: "alternate", href: entry.linkToAlternate }), - el("title", {}, entry.title), - el("summary", {}, entry.summary), - el("published", {}, entry.published), - el("updated", {}, entry.updated), - ), - ), - ); -} diff --git a/vhosts/blog/nuldoc-src/jsx/types.d.ts b/vhosts/blog/nuldoc-src/jsx/types.d.ts index 6a9d2b91..5d949d14 100644 --- a/vhosts/blog/nuldoc-src/jsx/types.d.ts +++ b/vhosts/blog/nuldoc-src/jsx/types.d.ts @@ -20,7 +20,18 @@ declare global { // deno-lint-ignore no-explicit-any | ((props: any) => FunctionComponentResult); + // TODO: HTML 用の element と XML 用の element を分ける interface IntrinsicElements { + // XML (Atom) + author: IntrinsicElementType; + entry: IntrinsicElementType; + feed: IntrinsicElementType & { xmlns: string }; + id: IntrinsicElementType; + name: IntrinsicElementType; + published: IntrinsicElementType; + summary: IntrinsicElementType; + updated: IntrinsicElementType; + // HTML a: IntrinsicElementType & { href?: string }; article: IntrinsicElementType; body: IntrinsicElementType; diff --git a/vhosts/blog/nuldoc-src/pages/AtomPage.tsx b/vhosts/blog/nuldoc-src/pages/AtomPage.tsx new file mode 100644 index 00000000..21c3bfaf --- /dev/null +++ b/vhosts/blog/nuldoc-src/pages/AtomPage.tsx @@ -0,0 +1,26 @@ +import { Feed } from "../generators/atom.ts"; + +export default function AtomPage({ feed }: { feed: Feed }) { + return ( + <feed xmlns="http://www.w3.org/2005/Atom"> + <id>{feed.id}</id> + <title>{feed.title}</title> + <link rel="alternate" href={feed.linkToAlternate} /> + <link rel="self" href={feed.linkToSelf} /> + <author> + <name>{feed.author}</name> + </author> + <updated>{feed.updated}</updated> + {feed.entries.map((entry) => ( + <entry> + <id>{entry.id}</id> + <link rel="alternate" href={entry.linkToAlternate} /> + <title>{entry.title}</title> + <summary>{entry.summary}</summary> + <published>{entry.published}</published> + <updated>{entry.updated}</updated> + </entry> + ))} + </feed> + ); +} |
