From 70a1fffacce3bef06562589b06f424d341807528 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Fri, 4 Jun 2021 16:14:36 -0300 Subject: module-ify flash pages --- src/page/flash.js | 267 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/page/index.js | 1 + src/upd8.js | 237 +----------------------------------------------- 3 files changed, 273 insertions(+), 232 deletions(-) create mode 100644 src/page/flash.js diff --git a/src/page/flash.js b/src/page/flash.js new file mode 100644 index 0000000..4ffaefc --- /dev/null +++ b/src/page/flash.js @@ -0,0 +1,267 @@ +// Flash page and index specifications. + +// Imports + +import fixWS from 'fix-whitespace'; + +import { + getLinkThemeString, + getThemeString +} from '../util/colors.js'; + +import * as html from '../util/html.js'; + +import { + getFlashLink +} from '../util/wiki-data.js'; + +// Page exports + +export function condition({wikiData}) { + return wikiData.wikiInfo.features.flashesAndGames; +} + +export function targets({wikiData}) { + return wikiData.flashData; +} + +export function write(flash, {wikiData}) { + const page = { + type: 'page', + path: ['flash', flash.directory], + page: ({ + fancifyFlashURL, + generateChronologyLinks, + generateCoverLink, + generatePreviousNextLinks, + getArtistString, + getFlashCover, + link, + strings, + transformInline + }) => ({ + title: strings('flashPage.title', {flash: flash.name}), + theme: getThemeString(flash.color, [ + `--flash-directory: ${flash.directory}` + ]), + + main: { + content: fixWS` +

${strings('flashPage.title', {flash: flash.name})}

+ ${generateCoverLink({ + src: getFlashCover(flash), + alt: strings('misc.alt.flashArt') + })} +

${strings('releaseInfo.released', {date: strings.count.date(flash.date)})}

+ ${(flash.page || flash.urls.length) && `

${strings('releaseInfo.playOn', { + links: strings.list.or([ + flash.page && getFlashLink(flash), + ...flash.urls + ].map(url => fancifyFlashURL(url, flash))) + })}

`} + ${flash.tracks.length && fixWS` +

Tracks featured in ${flash.name.replace(/\.$/, '')}:

+ + `} + ${flash.contributors.textContent && fixWS` +

+ ${strings('releaseInfo.contributors')} +
+ ${transformInline(flash.contributors.textContent)} +

+ `} + ${flash.contributors.length && fixWS` +

${strings('releaseInfo.contributors')}

+ + `} + ` + }, + + sidebarLeft: generateSidebarForFlash(flash, {link, strings, wikiData}), + nav: generateNavForFlash(flash, { + generateChronologyLinks, + generatePreviousNextLinks, + link, + strings, + wikiData + }) + }) + }; + + return [page]; +} + +export function writeTargetless({wikiData}) { + const { flashActData } = wikiData; + + const page = { + type: 'page', + path: ['flashIndex'], + page: ({ + getFlashGridHTML, + link, + strings + }) => ({ + title: strings('flashIndex.title'), + + main: { + classes: ['flash-index'], + content: fixWS` +

${strings('flashIndex.title')}

+
+

${strings('misc.jumpTo')}

+ +
+ ${flashActData.map((act, i) => fixWS` +

${link.flash(act.flashes[0], {text: act.name})}

+
+ ${getFlashGridHTML({ + entries: act.flashes.map(flash => ({item: flash})), + lazy: i === 0 ? 4 : true + })} +
+ `).join('\n')} + ` + }, + + nav: {simple: true} + }) + }; + + return [page]; +} + +// Utility functions + +function generateNavForFlash(flash, { + generateChronologyLinks, + generatePreviousNextLinks, + link, + strings, + wikiData +}) { + const { flashData, wikiInfo } = wikiData; + + const previousNextLinks = generatePreviousNextLinks(flash, { + data: flashData, + linkKey: 'flash' + }); + + return { + links: [ + { + path: ['localized.home'], + title: wikiInfo.shortName + }, + { + path: ['localized.flashIndex'], + title: strings('flashIndex.title') + }, + { + html: strings('flashPage.nav.flash', { + flash: link.flash(flash, {class: 'current'}) + }) + }, + previousNextLinks && + { + divider: false, + html: `(${previousNextLinks})` + } + ], + + content: fixWS` +
+ ${generateChronologyLinks(flash, { + headingString: 'misc.chronology.heading.flash', + contribKey: 'contributors', + getThings: artist => artist.flashes.asContributor + })} +
+ ` + }; +} + +function generateSidebarForFlash(flash, {link, strings, wikiData}) { + // all hard-coded, sorry :( + // this doesnt have a super portable implementation/design...yet!! + + const { flashActData } = wikiData; + + const act6 = flashActData.findIndex(act => act.name.startsWith('Act 6')); + const postCanon = flashActData.findIndex(act => act.name.includes('Post Canon')); + const outsideCanon = postCanon + flashActData.slice(postCanon).findIndex(act => !act.name.includes('Post Canon')); + const actIndex = flashActData.indexOf(flash.act); + const side = ( + (actIndex < 0) ? 0 : + (actIndex < act6) ? 1 : + (actIndex <= outsideCanon) ? 2 : + 3 + ); + const currentAct = flash && flash.act; + + return { + content: fixWS` +

${link.flashIndex('', {text: strings('flashIndex.title')})}

+
+ ${flashActData.filter(act => + act.name.startsWith('Act 1') || + act.name.startsWith('Act 6 Act 1') || + act.name.startsWith('Hiveswap') || + // Sorry not sorry -Yiffy + (({index = flashActData.indexOf(act)} = {}) => ( + index < act6 ? side === 1 : + index < outsideCanon ? side === 2 : + true + ))() + ).flatMap(act => [ + act.name.startsWith('Act 1') && html.tag('dt', + {class: ['side', side === 1 && 'current']}, + link.flash(act.flashes[0], {color: '#4ac925', text: `Side 1 (Acts 1-5)`})) + || act.name.startsWith('Act 6 Act 1') && html.tag('dt', + {class: ['side', side === 2 && 'current']}, + link.flash(act.flashes[0], {color: '#1076a2', text: `Side 2 (Acts 6-7)`})) + || act.name.startsWith('Hiveswap Act 1') && html.tag('dt', + {class: ['side', side === 3 && 'current']}, + link.flash(act.flashes[0], {color: '#008282', text: `Outside Canon (Misc. Games)`})), + (({index = flashActData.indexOf(act)} = {}) => ( + index < act6 ? side === 1 : + index < outsideCanon ? side === 2 : + true + ))() && html.tag('dt', + {class: act === currentAct && 'current'}, + link.flash(act.flashes[0], {text: act.name})), + act === currentAct && fixWS` +
    + ${act.flashes.map(f => html.tag('li', + {class: f === flash && 'current'}, + link.flash(f))).join('\n')} +
+ ` + ]).filter(Boolean).join('\n')} +
+ ` + }; +} diff --git a/src/page/index.js b/src/page/index.js index aa115c9..4ef5797 100644 --- a/src/page/index.js +++ b/src/page/index.js @@ -42,6 +42,7 @@ export * as album from './album.js'; export * as artist from './artist.js'; export * as artistAlias from './artist-alias.js'; +export * as flash from './flash.js'; export * as group from './group.js'; export * as homepage from './homepage.js'; export * as listing from './listing.js'; diff --git a/src/upd8.js b/src/upd8.js index 20bb329..40e763c 100755 --- a/src/upd8.js +++ b/src/upd8.js @@ -2215,238 +2215,6 @@ function generateRedirectPage(title, target, {strings}) { `; } -function writeFlashPages({wikiData}) { - const { flashData, wikiInfo } = wikiData; - - if (!wikiInfo.features.flashesAndGames) { - return; - } - - return [ - writeFlashIndex({wikiData}), - ...flashData.map(flash => writeFlashPage(flash, {wikiData})) - ]; -} - -function writeFlashIndex({wikiData}) { - const { flashActData } = wikiData; - - const page = { - type: 'page', - path: ['flashIndex'], - page: ({ - getFlashGridHTML, - link, - strings - }) => ({ - title: strings('flashIndex.title'), - - main: { - classes: ['flash-index'], - content: fixWS` -

${strings('flashIndex.title')}

-
-

${strings('misc.jumpTo')}

- -
- ${flashActData.map((act, i) => fixWS` -

${link.flash(act.flashes[0], {text: act.name})}

-
- ${getFlashGridHTML({ - entries: act.flashes.map(flash => ({item: flash})), - lazy: i === 0 ? 4 : true - })} -
- `).join('\n')} - ` - }, - - nav: {simple: true} - }) - }; - - return [page]; -} - -function writeFlashPage(flash, {wikiData}) { - const page = { - type: 'page', - path: ['flash', flash.directory], - page: ({ - generateCoverLink, - getArtistString, - getFlashCover, - link, - strings, - transformInline - }) => ({ - title: strings('flashPage.title', {flash: flash.name}), - theme: getThemeString(flash.color, [ - `--flash-directory: ${flash.directory}` - ]), - - main: { - content: fixWS` -

${strings('flashPage.title', {flash: flash.name})}

- ${generateCoverLink({ - src: getFlashCover(flash), - alt: strings('misc.alt.flashArt') - })} -

${strings('releaseInfo.released', {date: strings.count.date(flash.date)})}

- ${(flash.page || flash.urls.length) && `

${strings('releaseInfo.playOn', { - links: strings.list.or([ - flash.page && getFlashLink(flash), - ...flash.urls - ].map(url => fancifyFlashURL(url, flash, {strings}))) - })}

`} - ${flash.tracks.length && fixWS` -

Tracks featured in ${flash.name.replace(/\.$/, '')}:

- - `} - ${flash.contributors.textContent && fixWS` -

- ${strings('releaseInfo.contributors')} -
- ${transformInline(flash.contributors.textContent)} -

- `} - ${flash.contributors.length && fixWS` -

${strings('releaseInfo.contributors')}

- - `} - ` - }, - - sidebarLeft: generateSidebarForFlash(flash, {link, strings, wikiData}), - nav: generateNavForFlash(flash, {link, strings, wikiData}) - }) - }; - - return [page]; -} - -function generateNavForFlash(flash, {link, strings, wikiData}) { - const { flashData, wikiInfo } = wikiData; - - const previousNextLinks = generatePreviousNextLinks(flash, { - link, strings, - data: flashData, - linkKey: 'flash' - }); - - return { - links: [ - { - path: ['localized.home'], - title: wikiInfo.shortName - }, - { - path: ['localized.flashIndex'], - title: strings('flashIndex.title') - }, - { - html: strings('flashPage.nav.flash', { - flash: link.flash(flash, {class: 'current'}) - }) - }, - previousNextLinks && - { - divider: false, - html: `(${previousNextLinks})` - } - ], - - content: fixWS` -
- ${generateChronologyLinks(flash, { - link, strings, wikiData, - headingString: 'misc.chronology.heading.flash', - contribKey: 'contributors', - getThings: artist => artist.flashes.asContributor - })} -
- ` - }; -} - -function generateSidebarForFlash(flash, {link, strings, wikiData}) { - // all hard-coded, sorry :( - // this doesnt have a super portable implementation/design...yet!! - - const { flashActData } = wikiData; - - const act6 = flashActData.findIndex(act => act.name.startsWith('Act 6')); - const postCanon = flashActData.findIndex(act => act.name.includes('Post Canon')); - const outsideCanon = postCanon + flashActData.slice(postCanon).findIndex(act => !act.name.includes('Post Canon')); - const actIndex = flashActData.indexOf(flash.act); - const side = ( - (actIndex < 0) ? 0 : - (actIndex < act6) ? 1 : - (actIndex <= outsideCanon) ? 2 : - 3 - ); - const currentAct = flash && flash.act; - - return { - content: fixWS` -

${link.flashIndex('', {text: strings('flashIndex.title')})}

-
- ${flashActData.filter(act => - act.name.startsWith('Act 1') || - act.name.startsWith('Act 6 Act 1') || - act.name.startsWith('Hiveswap') || - // Sorry not sorry -Yiffy - (({index = flashActData.indexOf(act)} = {}) => ( - index < act6 ? side === 1 : - index < outsideCanon ? side === 2 : - true - ))() - ).flatMap(act => [ - act.name.startsWith('Act 1') && `
${link.flash(act.flashes[0], {color: '#4ac925', text: `Side 1 (Acts 1-5)`})}
` - || act.name.startsWith('Act 6 Act 1') && `
${link.flash(act.flashes[0], {color: '#1076a2', text: `Side 2 (Acts 6-7)`})}
` - || act.name.startsWith('Hiveswap Act 1') && `
${link.flash(act.flashes[0], {color: '#008282', text: `Outside Canon (Misc. Games)`})}
`, - (({index = flashActData.indexOf(act)} = {}) => ( - index < act6 ? side === 1 : - index < outsideCanon ? side === 2 : - true - ))() - && `
${link.flash(act.flashes[0], {text: act.name})}
`, - act === currentAct && fixWS` -
    - ${act.flashes.map(f => fixWS` -
  • ${link.flash(f)}
  • - `).join('\n')} -
- ` - ]).filter(Boolean).join('\n')} -
- ` - }; -} - function filterAlbumsByCommentary(albums) { return albums.filter(album => [album, ...album.tracks].some(x => x.commentary)); } @@ -3736,6 +3504,11 @@ async function main() { strings }); + bound.fancifyFlashURL = bindOpts(fancifyFlashURL, { + [bindOpts.bindIndex]: 2, + strings + }); + bound.getArtistString = bindOpts(getArtistString, { iconifyURL: bound.iconifyURL, link: bound.link, -- cgit 1.3.0-6-gf8a5