diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/content/dependencies/generateNewsIndexPage.js | 92 |
1 files changed, 91 insertions, 1 deletions
diff --git a/src/content/dependencies/generateNewsIndexPage.js b/src/content/dependencies/generateNewsIndexPage.js index 938d8be7..da497a7d 100644 --- a/src/content/dependencies/generateNewsIndexPage.js +++ b/src/content/dependencies/generateNewsIndexPage.js @@ -1,3 +1,93 @@ +import {stitchArrays} from '../../util/sugar.js'; +import {sortChronologically} from '../../util/wiki-data.js'; + export default { - generate() {}, + contentDependencies: [ + 'generatePageLayout', + 'linkNewsEntry', + 'transformContent', + ], + + extraDependencies: ['html', 'language', 'wikiData'], + + sprawl({newsData}) { + return {newsData}; + }, + + query({newsData}) { + return { + entries: + sortChronologically( + newsData.slice(), + {latestFirst: true}), + }; + }, + + relations(relation, query) { + const relations = {}; + + relations.layout = + relation('generatePageLayout'); + + relations.entryLinks = + query.entries + .map(entry => relation('linkNewsEntry', entry)); + + relations.viewRestLinks = + query.entries + .map(entry => + (entry.content === entry.contentShort + ? null + : relation('linkNewsEntry', entry))); + + relations.entryContents = + query.entries + .map(entry => relation('transformContent', entry.contentShort)); + + return relations; + }, + + data(query) { + return { + entryDates: + query.entries.map(entry => entry.date), + + entryDirectories: + query.entries.map(entry => entry.directory), + }; + }, + + generate(data, relations, {html, language}) { + return relations.layout.slots({ + title: language.$('newsIndex.title'), + headingMode: 'sticky', + + mainClasses: ['long-content', 'news-index'], + mainContent: + stitchArrays({ + entryLink: relations.entryLinks, + viewRestLink: relations.viewRestLinks, + content: relations.entryContents, + date: data.entryDates, + directory: data.entryDirectories, + }).map(({entryLink, viewRestLink, content, date, directory}) => + html.tag('article', {id: directory}, [ + html.tag('h2', [ + html.tag('time', language.formatDate(date)), + entryLink, + ]), + + content, + + viewRestLink + ?.slot('content', language.$('newsIndex.entry.viewRest')), + ])), + + navLinkStyle: 'hierarchical', + navLinks: [ + {auto: 'home'}, + {auto: 'current'}, + ], + }); + }, }; |