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
|
import { Config } from "../config.ts";
import { el, Element } from "../dom.ts";
import { stylesheetLinkElement } from "./utils.ts";
type Params = {
metaCopyrightYear: number;
metaDescription: string;
metaKeywords: string[];
metaTitle: string;
metaAtomFeedHref?: string;
requiresSyntaxHighlight: boolean;
};
export async function pageLayout(
{
metaCopyrightYear,
metaDescription,
metaKeywords,
metaTitle,
metaAtomFeedHref,
requiresSyntaxHighlight,
}: Params,
body: Element,
config: Config,
): Promise<Element> {
const head = el(
"head",
{},
metaElement({ charset: "UTF-8" }),
metaElement({
name: "viewport",
content: "width=device-width, initial-scale=1.0",
}),
metaElement({ name: "author", content: config.blog.author }),
metaElement({
name: "copyright",
content: `© ${metaCopyrightYear} ${config.blog.author}`,
}),
metaElement({ name: "description", content: metaDescription }),
...(metaKeywords.length === 0 ? [] : [
metaElement({ name: "keywords", content: metaKeywords.join(",") }),
]),
metaElement({ property: "og:type", content: "article" }),
metaElement({ property: "og:title", content: metaTitle }),
metaElement({ property: "og:description", content: metaDescription }),
metaElement({ property: "og:site_name", content: config.blog.siteName }),
metaElement({ property: "og:locale", content: "ja_JP" }),
...(metaAtomFeedHref
? [linkElement("alternate", metaAtomFeedHref, "application/atom+xml")]
: []),
linkElement("icon", "/favicon.svg", "image/svg+xml"),
el("title", {}, metaTitle),
await stylesheetLinkElement("/style.css", config),
...(
requiresSyntaxHighlight
? [await stylesheetLinkElement("/hl.css", config)]
: []
),
);
return el(
"html",
{ lang: "ja-JP" },
head,
body,
);
}
function metaElement(attrs: Record<string, string>): Element {
return el("meta", attrs);
}
function linkElement(
rel: string,
href: string,
type: string | null,
): Element {
const attrs: Record<string, string> = { rel: rel, href: href };
if (type !== null) {
attrs.type = type;
}
return el("link", attrs);
}
|