aboutsummaryrefslogtreecommitdiffhomepage
path: root/nuldoc-src/pages/tag.ts
blob: 3c1421f5603a307934cc055983de1455a4b4433b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import { globalFooter } from "../components/global_footer.ts";
import { globalHeader } from "../components/global_header.ts";
import { pageLayout } from "../components/page_layout.ts";
import { Config } from "../config.ts";
import { el, text } from "../dom.ts";
import { Page } from "../page.ts";
import { getPostCreatedDate, getPostUpdatedDate } from "./post.ts";
import { TaggedPage } from "./tagged_page.ts";

export interface TagPage extends Page {
  tagSlug: string;
  tagLabel: string;
}

export async function generateTagPage(
  tagSlug: string,
  pages: TaggedPage[],
  config: Config,
): Promise<TagPage> {
  const tagLabel =
    (config.blog.tagLabels as { [key: string]: string })[tagSlug];
  const pageTitle = `タグ「${tagLabel}」一覧`;

  const body = el(
    "body",
    [["class", "list"]],
    globalHeader(config),
    el(
      "main",
      [["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"]],
              text("Posted on "),
              el(
                "time",
                [["datetime", getPostCreatedDate(page)]],
                text(getPostCreatedDate(page)),
              ),
              ...(page.revisions.length > 1
                ? [
                  text(", updated on "),
                  el("time", [[
                    "datetime",
                    getPostUpdatedDate(page),
                  ]], text(getPostUpdatedDate(page))),
                ]
                : []),
            ),
          ),
        )
      ),
    ),
    globalFooter(config),
  );

  const html = await pageLayout(
    {
      metaCopyrightYear: parseInt(
        getPostCreatedDate(pages[pages.length - 1]).substring(0, 4),
      ),
      metaDescription: `タグ「${tagLabel}」のついた記事またはスライドの一覧`,
      metaKeywords: [tagLabel],
      metaTitle: `${pageTitle} | ${config.blog.siteName}`,
      requiresSyntaxHighlight: false,
    },
    body,
    config,
  );

  return {
    root: el("__root__", [], html),
    renderer: "html",
    destFilePath: `/tags/${tagSlug}/index.html`,
    href: `/tags/${tagSlug}/`,
    tagSlug: tagSlug,
    tagLabel: tagLabel,
  };
}