From 0e76e3af12ed53f27f0be8d96770da840141a3f0 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 19 Jul 2022 18:34:19 -0300 Subject: htmlify news pages --- src/page/news.js | 120 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 63 insertions(+), 57 deletions(-) (limited to 'src') diff --git a/src/page/news.js b/src/page/news.js index 478ff9d0..49cee7b9 100644 --- a/src/page/news.js +++ b/src/page/news.js @@ -1,13 +1,5 @@ -/** @format */ - // News entry & index page specifications. -// Imports - -import fixWS from 'fix-whitespace'; - -// Page exports - export function condition({wikiData}) { return wikiData.wikiInfo.enableNews; } @@ -22,30 +14,35 @@ export function write(entry, {wikiData}) { path: ['newsEntry', entry.directory], page: ({ generatePreviousNextLinks, - link, + html, language, + link, transformMultiline, }) => ({ title: language.$('newsEntryPage.title', {entry: entry.name}), main: { - content: fixWS` -
-

${language.$('newsEntryPage.title', { - entry: entry.name, - })}

-

${language.$('newsEntryPage.published', { - date: language.formatDate(entry.date), - })}

- ${transformMultiline(entry.content)} -
- `, + content: + html.tag('div', {class: 'long-content'}, [ + html.tag('h1', + language.$('newsEntryPage.title', { + entry: entry.name, + })), + + html.tag('p', + language.$('newsEntryPage.published', { + date: language.formatDate(entry.date), + })), + + transformMultiline(entry.content) + ]), }, nav: generateNewsEntryNav(entry, { generatePreviousNextLinks, - link, + html, language, + link, wikiData, }), }), @@ -60,35 +57,43 @@ export function writeTargetless({wikiData}) { const page = { type: 'page', path: ['newsIndex'], - page: ({link, language, transformMultiline}) => ({ + page: ({ + html, + language, + link, + transformMultiline, + }) => ({ title: language.$('newsIndex.title'), main: { - content: fixWS` -
-

${language.$('newsIndex.title')}

- ${newsData - .map( - (entry) => fixWS` -
-

${link.newsEntry(entry)}

- ${transformMultiline(entry.contentShort)} - ${ - entry.contentShort !== entry.content && - `

${link.newsEntry(entry, { - text: language.$( - 'newsIndex.entry.viewRest' - ), - })}

` - } -
- ` - ) - .join('\n')} -
- `, + content: + html.tag('div', + {class: ['long-content', 'news-index']}, + [ + html.tag('h1', + language.$('newsIndex.title')), + + ...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}, @@ -98,21 +103,22 @@ export function writeTargetless({wikiData}) { return [page]; } -// Utility functions - -function generateNewsEntryNav( - entry, - {generatePreviousNextLinks, link, language, wikiData} -) { - const {newsData} = wikiData; - +function generateNewsEntryNav(entry, { + generatePreviousNextLinks, + 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 = generatePreviousNextLinks(entry, { - link, - language, data: newsData.slice().reverse(), linkKey: 'newsEntry', + + html, + language, + link, }); return { -- cgit 1.3.0-6-gf8a5