aboutsummaryrefslogtreecommitdiffstats
path: root/src/server/template/atom.ts
blob: 82c9fe4adfaa0c74e732a83489c864bb1b1bf082 (plain) (blame)
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
106
107
108
109
110
111
112
113
114
import type { element, node } from "./vdom.js";
import t, { Base, Lang, Attribute as Attr } from "./xml.js";

export interface Attribute extends Attr, Base, Lang { }

export function feed(attr: Attribute,
	...content: element<"id" | "title" | "updated" | "author" |
		"link" | "author" | "category" | "contributor" | "generator"
		| "icon" | "logo" | "rights" | "subtitle" | "entry">[]
) {
	return t("feed", attr, ...content);
}

export function entry(
	attr: Attribute,
	...content: element<
		"id" | "title" | "updated" | "author" | "content" | "link" |
		"summary" | "category" | "contributor" | "rights" | "published" | "source">[]
) {
	return t("entry", attr, ...content);
}

export function author(attr: Attribute, ...content: [element<"name" | "email">, element<"name" | "email">]) {
	return t("author", attr, ...content);
}

export function contributor(attr: Attribute, ...content: [element<"name" | "email">, element<"name" | "email">]) {
	return t("contributor", attr, ...content);
}

export function id({ id, ...prop }: Attribute & { id: URL }) {
	return t("id", prop, id.href);
}

export function updated({ date, ...prop }: Attribute & { date: Date }) {
	return t("updated", prop, date.toISOString());
}

export function update({ date, ...prop }: Attribute & { date: Date } ) {
	return t("update", prop, date.toISOString());
}

export function icon(attr: Attribute, ...content: string[]) {
	return t("icon", attr, ...content);
}

export function logo(attr: Attribute, ...content: string[]) {
	return t("logo", attr, ...content);
}

export function name(attr: Attribute, content: string) {
	return t("name", attr, content);
}

export function email(attr: Attribute, content: string) {
	return t("email", attr, content);
}

interface TextAttribute extends Attribute {
	type?: string;
}

export function title(attr: TextAttribute, ...content: node[]) {
	return t("title", attr, ...content);
}

export function subtitle(attr: TextAttribute, ...content: string[]) {
	return t("subtitle", attr, ...content);
}

export function summary(attr: TextAttribute, ...content: string[]) {
	return t("summary", attr, ...content);
}

export function rights(attr: TextAttribute, ...content: string[]) {
	return t("rights", attr, ...content);
}

export function content(attr: TextAttribute, ...child: node[]) {
	return t("content", attr, ...child);
}


interface generatorAttribute extends Attribute {
	uri?: string;
	version?: string
}

export function generator(attr: generatorAttribute, ...content: string[]) {
	return t("generator", attr, ...content);
}

interface linkAttribute extends Attribute {
	href: URL;
	rel?: "alternate" | "enclosure" | "self" | "via";
	type?: string;
	hreflang?: string;
	title?: string;
	length?: number;
}

export function link(attr: linkAttribute) {
	return t("link", { ...attr, href: attr.href.href, length: "" + (attr.length ?? "") });
}

interface catAttribute extends Attribute {
	term: string;
	scheme?: URL;
	label?: string;
}

export function category(attr: catAttribute) {
	return t("category", { ...attr, href: attr.scheme?.href });
}