From bce6a52f44b6be8de1d7ed42150d051c25e63fb7 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Wed, 26 Jul 2023 10:13:46 -0300 Subject: content: generateWikiHomePage (layout besides content) --- .../dependencies/generateWikiHomeNewsBox.js | 76 ++++++++++++++++++ src/content/dependencies/generateWikiHomePage.js | 91 ++++++++++++++++++++++ src/content/dependencies/linkCommentaryIndex.js | 12 +++ src/content/dependencies/linkFlashIndex.js | 12 +++ src/content/dependencies/linkNewsIndex.js | 12 +++ src/content/dependencies/linkWikiHome.js | 20 +++++ 6 files changed, 223 insertions(+) create mode 100644 src/content/dependencies/generateWikiHomeNewsBox.js create mode 100644 src/content/dependencies/generateWikiHomePage.js create mode 100644 src/content/dependencies/linkCommentaryIndex.js create mode 100644 src/content/dependencies/linkFlashIndex.js create mode 100644 src/content/dependencies/linkNewsIndex.js create mode 100644 src/content/dependencies/linkWikiHome.js (limited to 'src/content') diff --git a/src/content/dependencies/generateWikiHomeNewsBox.js b/src/content/dependencies/generateWikiHomeNewsBox.js new file mode 100644 index 00000000..a1efb810 --- /dev/null +++ b/src/content/dependencies/generateWikiHomeNewsBox.js @@ -0,0 +1,76 @@ +import {empty, stitchArrays} from '../../util/sugar.js'; + +export default { + contentDependencies: ['linkNewsEntry', 'transformContent'], + extraDependencies: ['html', 'language', 'wikiData'], + + sprawl({newsData}) { + return { + entries: newsData.slice(0, 3), + }; + }, + + relations(relation, sprawl) { + return { + entryContents: + sprawl.entries + .map(entry => relation('transformContent', entry.contentShort)), + + entryMainLinks: + sprawl.entries + .map(entry => relation('linkNewsEntry', entry)), + + entryReadMoreLinks: + sprawl.entries + .map(entry => + entry.contentShort !== entry.content && + relation('linkNewsEntry', entry)), + }; + }, + + data(sprawl) { + return { + entryDates: + sprawl.entries + .map(entry => entry.date), + } + }, + + generate(data, relations, {html, language}) { + if (empty(relations.entryContents)) { + return html.blank(); + } + + return { + content: [ + html.tag('h1', language.$('homepage.news.title')), + + stitchArrays({ + date: data.entryDates, + content: relations.entryContents, + mainLink: relations.entryMainLinks, + readMoreLink: relations.entryReadMoreLinks, + }).map(({ + date, + content, + mainLink, + readMoreLink, + }, index) => + html.tag('article', + {class: ['news-entry', index === 0 && 'first-news-entry']}, + [ + html.tag('h2', [ + html.tag('time', language.formatDate(date)), + mainLink, + ]), + + content.slot('thumb', 'medium'), + + readMoreLink?.slots({ + content: language.$('homepage.news.entry.viewRest'), + }), + ])), + ], + }; + }, +}; diff --git a/src/content/dependencies/generateWikiHomePage.js b/src/content/dependencies/generateWikiHomePage.js new file mode 100644 index 00000000..666c3f26 --- /dev/null +++ b/src/content/dependencies/generateWikiHomePage.js @@ -0,0 +1,91 @@ +export default { + contentDependencies: [ + 'generatePageLayout', + 'generateWikiHomeNewsBox', + 'transformContent', + ], + + extraDependencies: ['wikiData'], + + sprawl({wikiInfo}) { + return { + wikiName: wikiInfo.name, + + enableNews: wikiInfo.enableNews, + }; + }, + + relations(relation, sprawl, homepageLayout) { + const relations = {}; + + relations.layout = + relation('generatePageLayout'); + + if (homepageLayout.sidebarContent) { + relations.customSidebarContent = + relation('transformContent', homepageLayout.sidebarContent); + } + + if (sprawl.enableNews) { + relations.newsSidebarBox = + relation('generateWikiHomeNewsBox'); + } + + if (homepageLayout.navbarLinks) { + relations.customNavLinkContents = + homepageLayout.navbarLinks + .map(content => relation('transformContent', content)); + } + + return relations; + }, + + data(sprawl) { + return { + wikiName: sprawl.wikiName, + }; + }, + + generate(data, relations) { + return relations.layout.slots({ + title: data.wikiName, + showWikiNameInTitle: false, + + mainClasses: ['top-index'], + headingMode: 'static', + + mainContent: [], + + leftSidebarCollapse: false, + leftSidebarWide: true, + + leftSidebarMultiple: [ + (relations.customSidebarContent + ? { + content: + relations.customSidebarContent + .slot('mode', 'multiline'), + } + : null), + + relations.newsSidebarBox ?? null, + ], + + navLinkStyle: 'index', + navLinks: [ + {auto: 'home', current: true}, + + ...( + relations.customNavLinkContents + ?.map(content => ({ + html: + content.slots({ + mode: 'inline', + preferShortLinkNames: true, + }), + })) + ?? []), + ], + }); + }, +}; diff --git a/src/content/dependencies/linkCommentaryIndex.js b/src/content/dependencies/linkCommentaryIndex.js new file mode 100644 index 00000000..5568ff84 --- /dev/null +++ b/src/content/dependencies/linkCommentaryIndex.js @@ -0,0 +1,12 @@ +export default { + contentDependencies: ['linkStationaryIndex'], + + relations: (relation) => + ({link: + relation( + 'linkStationaryIndex', + 'localized.commentaryIndex', + 'commentaryIndex.title')}), + + generate: (relations) => relations.link, +}; diff --git a/src/content/dependencies/linkFlashIndex.js b/src/content/dependencies/linkFlashIndex.js new file mode 100644 index 00000000..6dd0710e --- /dev/null +++ b/src/content/dependencies/linkFlashIndex.js @@ -0,0 +1,12 @@ +export default { + contentDependencies: ['linkStationaryIndex'], + + relations: (relation) => + ({link: + relation( + 'linkStationaryIndex', + 'localized.flashIndex', + 'flashIndex.title')}), + + generate: (relations) => relations.link, +}; diff --git a/src/content/dependencies/linkNewsIndex.js b/src/content/dependencies/linkNewsIndex.js new file mode 100644 index 00000000..e911a384 --- /dev/null +++ b/src/content/dependencies/linkNewsIndex.js @@ -0,0 +1,12 @@ +export default { + contentDependencies: ['linkStationaryIndex'], + + relations: (relation) => + ({link: + relation( + 'linkStationaryIndex', + 'localized.newsIndex', + 'newsIndex.title')}), + + generate: (relations) => relations.link, +}; diff --git a/src/content/dependencies/linkWikiHome.js b/src/content/dependencies/linkWikiHome.js new file mode 100644 index 00000000..06ec6438 --- /dev/null +++ b/src/content/dependencies/linkWikiHome.js @@ -0,0 +1,20 @@ +export default { + contentDependencies: ['linkStationaryIndex'], + extraDependencies: ['wikiData'], + + sprawl({wikiInfo}) { + return {wikiShortName: wikiInfo.nameShort}; + }, + + relations: (relation) => + ({link: relation('linkTemplate')}), + + data: (sprawl) => + ({wikiShortName: sprawl.wikiShortName}), + + generate: (data, relations) => + relations.link.slots({ + path: ['home'], + content: data.wikiShortName, + }), +}; -- cgit 1.3.0-6-gf8a5