From a735545f1442d9aab870ce34c76d43487f7ed547 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Fri, 4 Jun 2021 15:26:03 -0300 Subject: module-ify homepage --- src/page/homepage.js | 127 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/page/index.js | 1 + 2 files changed, 128 insertions(+) create mode 100644 src/page/homepage.js (limited to 'src/page') diff --git a/src/page/homepage.js b/src/page/homepage.js new file mode 100644 index 00000000..d1dcc680 --- /dev/null +++ b/src/page/homepage.js @@ -0,0 +1,127 @@ +// Homepage specification. + +// Imports + +import fixWS from 'fix-whitespace'; + +import { + getLinkThemeString +} from '../util/colors.js'; + +import find from '../util/find.js'; + +import * as html from '../util/html.js'; + +import { + getNewAdditions, + getNewReleases +} from '../util/wiki-data.js'; + +// Page exports + +export function writeTargetless({wikiData}) { + const { newsData, staticPageData, homepageInfo, wikiInfo } = wikiData; + + const page = { + type: 'page', + path: ['home'], + page: ({ + getAlbumGridHTML, + link, + strings, + to, + transformInline, + transformMultiline + }) => ({ + title: wikiInfo.name, + + meta: { + description: wikiInfo.description + }, + + main: { + classes: ['top-index'], + content: fixWS` +

${wikiInfo.name}

+ ${homepageInfo.rows.map((row, i) => fixWS` +
+

${row.name}

+ ${row.type === 'albums' && fixWS` +
+ ${getAlbumGridHTML({ + entries: ( + row.group === 'new-releases' ? getNewReleases(row.groupCount, {wikiData}) : + row.group === 'new-additions' ? getNewAdditions(row.groupCount, {wikiData}) : + ((find.group(row.group, {wikiData})?.albums || []) + .slice() + .reverse() + .slice(0, row.groupCount) + .map(album => ({item: album}))) + ).concat(row.albums + .map(album => find.album(album, {wikiData})) + .map(album => ({item: album})) + ), + lazy: i > 0 + })} + ${row.actions.length && fixWS` +
+ ${row.actions.map(action => transformInline(action) + .replace(' + `} +
+ `} +
+ `).join('\n')} + ` + }, + + sidebarLeft: homepageInfo.sidebar && { + wide: true, + collapse: false, + // This is a pretty filthy hack! 8ut otherwise, the [[news]] part + // gets treated like it's a reference to the track named "news", + // which o8viously isn't what we're going for. Gotta catch that + // 8efore we pass it to transformMultiline, 'cuz otherwise it'll + // get repl8ced with just the word "news" (or anything else that + // transformMultiline does with references it can't match) -- and + // we can't match that for replacing it with the news column! + // + // And no, I will not make [[news]] into part of transformMultiline + // (even though that would 8e hilarious). + content: (transformMultiline(homepageInfo.sidebar.replace('[[news]]', '__GENERATE_NEWS__')) + .replace('

__GENERATE_NEWS__

', wikiInfo.features.news ? fixWS` +

${strings('homepage.news.title')}

+ ${newsData.slice(0, 3).map((entry, i) => html.tag('article', + {class: ['news-entry', i === 0 && 'first-news-entry']}, + fixWS` +

${link.newsEntry(entry)}

+ ${transformMultiline(entry.bodyShort)} + ${entry.bodyShort !== entry.body && link.newsEntry(entry, { + text: strings('homepage.news.entry.viewRest') + })} + `)).join('\n')} + ` : `

News requested in content description but this feature isn't enabled

`)) + }, + + nav: { + content: fixWS` +

+ ${[ + link.home('', {text: wikiInfo.shortName, class: 'current', to}), + wikiInfo.features.listings && + link.listingIndex('', {text: strings('listingIndex.title'), to}), + wikiInfo.features.news && + link.newsIndex('', {text: strings('newsIndex.title'), to}), + wikiInfo.features.flashesAndGames && + link.flashIndex('', {text: strings('flashIndex.title'), to}), + ...staticPageData.filter(page => page.listed).map(link.staticPage) + ].filter(Boolean).map(link => `${link}`).join('\n')} +

+ ` + } + }) + }; + + return [page]; +} diff --git a/src/page/index.js b/src/page/index.js index 42204947..c5e10631 100644 --- a/src/page/index.js +++ b/src/page/index.js @@ -43,6 +43,7 @@ export * as album from './album.js'; export * as artist from './artist.js'; export * as artistAlias from './artist-alias.js'; export * as group from './group.js'; +export * as homepage from './homepage.js'; export * as static from './static.js'; export * as news from './news.js'; export * as track from './track.js'; -- cgit 1.3.0-6-gf8a5