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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
// News entry & index page specifications.
export const description = `per-entry news pages & index`;
export function condition({wikiData}) {
return wikiData.wikiInfo.enableNews;
}
export function targets({wikiData}) {
return wikiData.newsData;
}
export function write(entry, {wikiData}) {
const page = {
type: 'page',
path: ['newsEntry', entry.directory],
page: ({
generateNavigationLinks,
html,
language,
link,
transformMultiline,
}) => ({
title: language.$('newsEntryPage.title', {entry: entry.name}),
main: {
classes: ['long-content'],
headingMode: 'sticky',
content: [
html.tag('p',
language.$('newsEntryPage.published', {
date: language.formatDate(entry.date),
})),
transformMultiline(entry.content),
],
},
nav: generateNewsEntryNav(entry, {
generateNavigationLinks,
html,
language,
link,
wikiData,
}),
}),
};
return [page];
}
export function writeTargetless({wikiData}) {
const {newsData} = wikiData;
const page = {
type: 'page',
path: ['newsIndex'],
page: ({
html,
language,
link,
transformMultiline,
}) => ({
title: language.$('newsIndex.title'),
main: {
classes: ['long-content', 'news-index'],
headingMode: 'sticky',
content:
newsData.map(entry =>
html.tag('article',
{id: entry.directory},
[
html.tag('h2', [
html.tag('time',
language.formatDate(entry.date)),
link.newsEntry(entry),
]),
transformMultiline(entry.contentShort),
entry.contentShort !== entry.content &&
html.tag('p',
link.newsEntry(entry, {
text: language.$(
'newsIndex.entry.viewRest'
),
})),
])),
},
nav: {simple: true},
}),
};
return [page];
}
function generateNewsEntryNav(entry, {
generateNavigationLinks,
html,
language,
link,
wikiData: {newsData},
}) {
// The newsData list is sorted reverse chronologically (newest ones first),
// so the way we find next/previous entries is flipped from normal.
const previousNextLinks = generateNavigationLinks(entry, {
data: newsData.slice().reverse(),
linkKey: 'newsEntry',
html,
language,
link,
});
return {
linkContainerClasses: ['nav-links-hierarchy'],
links: [
{toHome: true},
{
path: ['localized.newsIndex'],
title: language.$('newsEntryPage.nav.news'),
},
{
html: language.$('newsEntryPage.nav.entry', {
date: language.formatDate(entry.date),
entry: link.newsEntry(entry, {class: 'current'}),
}),
},
previousNextLinks && {
divider: false,
html: `(${previousNextLinks})`,
},
],
};
}
|