From 69bfe1697e5513d49b3dcf1e64a0e82c512cbdc8 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 8 Aug 2023 10:00:43 -0300 Subject: css, content: transformContent: separate images from container --- src/content/dependencies/transformContent.js | 16 ++++++++-------- src/static/site4.css | 3 +-- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/content/dependencies/transformContent.js b/src/content/dependencies/transformContent.js index eed0088..fef74e8 100644 --- a/src/content/dependencies/transformContent.js +++ b/src/content/dependencies/transformContent.js @@ -351,14 +351,14 @@ export default { return { type: 'image', data: - image.slots({ - src, - class: 'content-image', - link: link ?? true, - width: width ?? null, - height: height ?? null, - thumb: slots.thumb, - }), + html.tag('div', {class: 'content-image'}, + image.slots({ + src, + link: link ?? true, + width: width ?? null, + height: height ?? null, + thumb: slots.thumb, + })), }; } diff --git a/src/static/site4.css b/src/static/site4.css index c9843bc..fc4f148 100644 --- a/src/static/site4.css +++ b/src/static/site4.css @@ -539,8 +539,7 @@ p .current { display: none; } -a.box.content-image { - display: block; +.content-image { margin-top: 1em; margin-bottom: 1em; } -- cgit 1.3.0-6-gf8a5 From a58b9dd2c15b56fcb8697013afb86238af4ba374 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 8 Aug 2023 10:04:44 -0300 Subject: css: fit any .image-container to parent .square --- src/static/site4.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/static/site4.css b/src/static/site4.css index fc4f148..dd6f104 100644 --- a/src/static/site4.css +++ b/src/static/site4.css @@ -558,7 +558,7 @@ a.box img { height: auto; } -a.box .image-container.placeholder-image { +a.box .square .image-container { width: 100%; height: 100%; } -- cgit 1.3.0-6-gf8a5 From 3ac8ca7f5c6b099f9917809829a8992d6f2926a0 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 8 Aug 2023 10:43:13 -0300 Subject: improve --lang-path help message --- src/upd8.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/upd8.js b/src/upd8.js index 11ede7b..fabda27 100755 --- a/src/upd8.js +++ b/src/upd8.js @@ -174,7 +174,7 @@ async function main() { // 8uild with the default (English) strings if this path is left // unspecified. 'lang-path': { - help: `Specify path to language directory, including JSON files that mapping internal string keys to localized language content, and various language metadata`, + help: `Specify path to language directory, including JSON files that mapping internal string keys to localized language content, and various language metadata\n\nOptional for wiki building, unless the wiki's default language is not English; may be provided via the HSMUSIC_LANG environment variable instead`, type: 'value', }, -- cgit 1.3.0-6-gf8a5 From 7ddefc6e44791397b9aadac781dbfa7c1536bdd5 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 8 Aug 2023 10:43:48 -0300 Subject: bulid: static-build: restore generateRedirectHTML, touch up redirect code --- src/write/build-modes/static-build.js | 78 +++++++++++++++++++++++------------ 1 file changed, 51 insertions(+), 27 deletions(-) diff --git a/src/write/build-modes/static-build.js b/src/write/build-modes/static-build.js index bf722bf..8fb60cd 100644 --- a/src/write/build-modes/static-build.js +++ b/src/write/build-modes/static-build.js @@ -78,6 +78,36 @@ export function getCLIOptions() { }; } +function generateRedirectHTML(title, target, {language}) { + return `\n` + html.tag('html', [ + html.tag('head', [ + html.tag('title', language.$('redirectPage.title', {title})), + html.tag('meta', {charset: 'utf-8'}), + + html.tag('meta', { + 'http-equiv': 'refresh', + content: `0;url=${target}`, + }), + + // TODO: Is this OK for localized pages? + html.tag('link', { + rel: 'canonical', + href: target, + }), + ]), + + html.tag('body', + html.tag('main', [ + html.tag('h1', + language.$('redirectPage.title', {title})), + html.tag('p', + language.$('redirectPage.infoLine', { + target: html.tag('a', {href: target}, target), + })), + ])), + ]); +} + export async function go({ cliOptions, _dataPath, @@ -323,7 +353,6 @@ export async function go({ }); }), - /* ...redirectWrites.map(({fromPath, toPath, title: titleFn}) => () => { const title = titleFn({ language, @@ -348,7 +377,6 @@ export async function go({ })), }); }), - */ ], queueSize)); }; @@ -473,31 +501,26 @@ async function writeSharedFilesAndPages({ const {groupData, wikiInfo} = wikiData; return progressPromiseAll(`Writing files & pages shared across languages.`, [ - /* groupData?.some((group) => group.directory === 'fandom') && - redirect( - 'Fandom - Gallery', - 'albums/fandom', - 'localized.groupGallery', - 'fandom' - ), + redirect({ + title: 'Fandom - Gallery', + from: 'albums/fandom', + to: ['localized.groupGallery', 'fandom'], + }), groupData?.some((group) => group.directory === 'official') && - redirect( - 'Official - Gallery', - 'albums/official', - 'localized.groupGallery', - 'official' - ), + redirect({ + title: 'Official - Gallery', + from: 'albums/official', + to: ['localized.groupGallery', 'official'], + }), wikiInfo.enableListings && - redirect( - 'Album Commentary', - 'list/all-commentary', - 'localized.commentaryIndex', - '' - ), - */ + redirect({ + title: 'Album Commentary', + from: 'list/all-commentary', + to: ['localized.commentaryIndex'], + }), wikiDataJSON && writeFile( @@ -505,11 +528,12 @@ async function writeSharedFilesAndPages({ wikiDataJSON), ].filter(Boolean)); - async function redirect(title, from, urlKey, directory) { - const target = path.relative( - from, - urls.from('shared.root').to(urlKey, directory) - ); + async function redirect({title, from, to: toPath}) { + const target = + path.relative( + from, + urls.from('shared.root').to(...toPath)); + const content = generateRedirectHTML(title, target, {language}); await mkdir(path.join(outputPath, from), {recursive: true}); await writeFile(path.join(outputPath, from, 'index.html'), content); -- cgit 1.3.0-6-gf8a5 From f2e6da9c339b9b4b862d9070188f4b0ba07baf45 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 8 Aug 2023 10:44:06 -0300 Subject: write: static-build: ensure output directory exists first of all --- src/write/build-modes/static-build.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/write/build-modes/static-build.js b/src/write/build-modes/static-build.js index 8fb60cd..60614c2 100644 --- a/src/write/build-modes/static-build.js +++ b/src/write/build-modes/static-build.js @@ -154,6 +154,8 @@ export async function go({ const writeAll = empty(selectedPageFlags) || selectedPageFlags.includes('all'); logInfo`Writing site pages: ${writeAll ? 'all' : selectedPageFlags.join(', ')}`; + await mkdir(outputPath, {recursive: true}); + await writeSymlinks({ srcRootPath, mediaPath, -- cgit 1.3.0-6-gf8a5 From 8f39a21ef27f8b66cd49c01e38937d133f13859d Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 8 Aug 2023 11:03:25 -0300 Subject: content: move hard-coded redirects into page files --- src/page/album.js | 11 +++++++++++ src/page/group.js | 18 ++++++++++++++++++ src/write/build-modes/static-build.js | 32 -------------------------------- 3 files changed, 29 insertions(+), 32 deletions(-) diff --git a/src/page/album.js b/src/page/album.js index a8e0b59..1d5c7c0 100644 --- a/src/page/album.js +++ b/src/page/album.js @@ -55,6 +55,17 @@ export function pathsForTarget(album) { ]; } +export function pathsTargetless({wikiData: {wikiInfo}}) { + return [ + wikiInfo.canonicalBase === 'https://hsmusic.wiki/' && + { + type: 'redirect', + fromPath: ['path', 'list/all-commentary/'], + toPath: ['commentaryIndex'], + }, + ]; +} + /* export function write(album, {wikiData}) { const getSocialEmbedDescription = ({ diff --git a/src/page/group.js b/src/page/group.js index 4d5f91c..8795e15 100644 --- a/src/page/group.js +++ b/src/page/group.js @@ -40,3 +40,21 @@ export function pathsForTarget(group) { }, ]; } + +export function pathsTargetless({wikiData: {wikiInfo}}) { + return [ + wikiInfo.canonicalBase === 'https://hsmusic.wiki/' && + { + type: 'redirect', + fromPath: ['path', 'albums/fandom/'], + toPath: ['groupGallery', 'fandom'], + }, + + wikiInfo.canonicalBase === 'https://hsmusic.wiki/' && + { + type: 'redirect', + fromPath: ['path', 'albums/official/'], + toPath: ['groupGallery', 'official'], + }, + ]; +} diff --git a/src/write/build-modes/static-build.js b/src/write/build-modes/static-build.js index 60614c2..dc2bb2c 100644 --- a/src/write/build-modes/static-build.js +++ b/src/write/build-modes/static-build.js @@ -503,41 +503,9 @@ async function writeSharedFilesAndPages({ const {groupData, wikiInfo} = wikiData; return progressPromiseAll(`Writing files & pages shared across languages.`, [ - groupData?.some((group) => group.directory === 'fandom') && - redirect({ - title: 'Fandom - Gallery', - from: 'albums/fandom', - to: ['localized.groupGallery', 'fandom'], - }), - - groupData?.some((group) => group.directory === 'official') && - redirect({ - title: 'Official - Gallery', - from: 'albums/official', - to: ['localized.groupGallery', 'official'], - }), - - wikiInfo.enableListings && - redirect({ - title: 'Album Commentary', - from: 'list/all-commentary', - to: ['localized.commentaryIndex'], - }), - wikiDataJSON && writeFile( path.join(outputPath, 'data.json'), wikiDataJSON), ].filter(Boolean)); - - async function redirect({title, from, to: toPath}) { - const target = - path.relative( - from, - urls.from('shared.root').to(...toPath)); - - const content = generateRedirectHTML(title, target, {language}); - await mkdir(path.join(outputPath, from), {recursive: true}); - await writeFile(path.join(outputPath, from, 'index.html'), content); - } } -- cgit 1.3.0-6-gf8a5 From 4236b4f348e14be2b78496c8d1c1c60942aa3515 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 8 Aug 2023 11:21:46 -0300 Subject: content: generateCommentaryIndexPage --- .../dependencies/generateCommentaryIndexPage.js | 102 +++++++++++++++++++++ src/page/album.js | 6 ++ 2 files changed, 108 insertions(+) create mode 100644 src/content/dependencies/generateCommentaryIndexPage.js diff --git a/src/content/dependencies/generateCommentaryIndexPage.js b/src/content/dependencies/generateCommentaryIndexPage.js new file mode 100644 index 0000000..0cb5a40 --- /dev/null +++ b/src/content/dependencies/generateCommentaryIndexPage.js @@ -0,0 +1,102 @@ +import {accumulateSum, stitchArrays} from '../../util/sugar.js'; +import {filterMultipleArrays, sortChronologically} from '../../util/wiki-data.js'; + +export default { + contentDependencies: ['generatePageLayout', 'linkAlbumCommentary'], + extraDependencies: ['html', 'language', 'wikiData'], + + sprawl({albumData}) { + return {albumData}; + }, + + query(sprawl) { + const query = {}; + + query.albums = + sortChronologically(sprawl.albumData.slice()); + + const entries = + query.albums.map(album => + [album, ...album.tracks] + .filter(({commentary}) => commentary) + .map(({commentary}) => commentary)); + + query.wordCounts = + entries.map(entries => + accumulateSum( + entries, + entry => entry.split(' ').length)); + + query.entryCounts = + entries.map(entries => entries.length); + + filterMultipleArrays(query.albums, query.wordCounts, query.entryCounts, + (album, wordCount, entryCount) => entryCount >= 1); + + return query; + }, + + relations(relation, query) { + return { + layout: + relation('generatePageLayout'), + + albumLinks: + query.albums + .map(album => relation('linkAlbumCommentary', album)), + }; + }, + + data(query) { + return { + wordCounts: query.wordCounts, + entryCounts: query.entryCounts, + + totalWordCount: accumulateSum(query.wordCounts), + totalEntryCount: accumulateSum(query.entryCounts), + }; + }, + + generate(data, relations, {html, language}) { + return relations.layout.slots({ + title: language.$('commentaryIndex.title'), + + headingMode: 'static', + + mainClasses: ['long-content'], + mainContent: [ + html.tag('p', language.$('commentaryIndex.infoLine', { + words: + html.tag('b', + language.formatWordCount(data.totalWordCount, {unit: true})), + + entries: + html.tag('b', + language.countCommentaryEntries(data.totalEntryCount, {unit: true})), + })), + + html.tag('p', + language.$('commentaryIndex.albumList.title')), + + html.tag('ul', + stitchArrays({ + albumLink: relations.albumLinks, + wordCount: data.wordCounts, + entryCount: data.entryCounts, + }).map(({albumLink, wordCount, entryCount}) => + html.tag('li', + language.$('commentaryIndex.albumList.item', { + album: albumLink, + words: language.formatWordCount(wordCount, {unit: true}), + entries: language.countCommentaryEntries(entryCount, {unit: true}), + })))), + ], + + navLinkStyle: 'hierarchical', + navLinks: [ + {auto: 'home'}, + {auto: 'current'}, + ], + }); + }, +}; diff --git a/src/page/album.js b/src/page/album.js index 1d5c7c0..edde73a 100644 --- a/src/page/album.js +++ b/src/page/album.js @@ -57,6 +57,12 @@ export function pathsForTarget(album) { export function pathsTargetless({wikiData: {wikiInfo}}) { return [ + { + type: 'page', + path: ['commentaryIndex'], + contentFunction: {name: 'generateCommentaryIndexPage'}, + }, + wikiInfo.canonicalBase === 'https://hsmusic.wiki/' && { type: 'redirect', -- cgit 1.3.0-6-gf8a5 From f65bbab508cebdbaffd188366e983945d73abd4a Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 8 Aug 2023 11:44:41 -0300 Subject: content: dedicated arbitrary page URL key This fixes getPageSubdirectoryPrefix thinking we're deeper than we really are. --- src/page/album.js | 2 +- src/page/group.js | 4 ++-- src/url-spec.js | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/page/album.js b/src/page/album.js index edde73a..4ed5bcb 100644 --- a/src/page/album.js +++ b/src/page/album.js @@ -66,7 +66,7 @@ export function pathsTargetless({wikiData: {wikiInfo}}) { wikiInfo.canonicalBase === 'https://hsmusic.wiki/' && { type: 'redirect', - fromPath: ['path', 'list/all-commentary/'], + fromPath: ['page', 'list/all-commentary'], toPath: ['commentaryIndex'], }, ]; diff --git a/src/page/group.js b/src/page/group.js index 8795e15..e1ed418 100644 --- a/src/page/group.js +++ b/src/page/group.js @@ -46,14 +46,14 @@ export function pathsTargetless({wikiData: {wikiInfo}}) { wikiInfo.canonicalBase === 'https://hsmusic.wiki/' && { type: 'redirect', - fromPath: ['path', 'albums/fandom/'], + fromPath: ['page', 'albums/fandom'], toPath: ['groupGallery', 'fandom'], }, wikiInfo.canonicalBase === 'https://hsmusic.wiki/' && { type: 'redirect', - fromPath: ['path', 'albums/official/'], + fromPath: ['page', 'albums/official'], toPath: ['groupGallery', 'official'], }, ]; diff --git a/src/url-spec.js b/src/url-spec.js index d1e347e..8340f19 100644 --- a/src/url-spec.js +++ b/src/url-spec.js @@ -21,6 +21,7 @@ const urlSpec = { paths: { root: '', path: '<>', + page: '<>/', home: '', -- cgit 1.3.0-6-gf8a5 From 725482638dcc96632c3a9cf2b885f4128c50a1c1 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 8 Aug 2023 11:46:44 -0300 Subject: write, content: restore & handle redirect titles properly --- src/page/album.js | 1 + src/page/artist-alias.js | 2 +- src/page/group.js | 2 ++ src/write/build-modes/live-dev-server.js | 6 +++++- src/write/build-modes/static-build.js | 6 ++---- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/page/album.js b/src/page/album.js index 4ed5bcb..3b2d02d 100644 --- a/src/page/album.js +++ b/src/page/album.js @@ -68,6 +68,7 @@ export function pathsTargetless({wikiData: {wikiInfo}}) { type: 'redirect', fromPath: ['page', 'list/all-commentary'], toPath: ['commentaryIndex'], + title: 'Album Commentary', }, ]; } diff --git a/src/page/artist-alias.js b/src/page/artist-alias.js index 9e9fdf5..23513ce 100644 --- a/src/page/artist-alias.js +++ b/src/page/artist-alias.js @@ -15,7 +15,7 @@ export function pathsForTarget(aliasArtist) { type: 'redirect', fromPath: ['artist', aliasArtist.directory], toPath: ['artist', aliasedArtist.directory], - title: () => aliasedArtist.name, + title: aliasedArtist.name, }, ]; } diff --git a/src/page/group.js b/src/page/group.js index e1ed418..fa6c1c9 100644 --- a/src/page/group.js +++ b/src/page/group.js @@ -48,6 +48,7 @@ export function pathsTargetless({wikiData: {wikiInfo}}) { type: 'redirect', fromPath: ['page', 'albums/fandom'], toPath: ['groupGallery', 'fandom'], + title: 'Fandom - Gallery', }, wikiInfo.canonicalBase === 'https://hsmusic.wiki/' && @@ -55,6 +56,7 @@ export function pathsTargetless({wikiData: {wikiInfo}}) { type: 'redirect', fromPath: ['page', 'albums/official'], toPath: ['groupGallery', 'official'], + title: 'Official - Gallery', }, ]; } diff --git a/src/write/build-modes/live-dev-server.js b/src/write/build-modes/live-dev-server.js index a87da27..edee326 100644 --- a/src/write/build-modes/live-dev-server.js +++ b/src/write/build-modes/live-dev-server.js @@ -321,6 +321,10 @@ export async function go({ try { if (page.type === 'redirect') { + const title = + page.title ?? + page.getTitle?.({language}); + const target = to('localized.' + page.toPath[0], ...page.toPath.slice(1)); response.writeHead(301, { @@ -328,7 +332,7 @@ export async function go({ 'Location': target, }); - const redirectHTML = generateRedirectHTML(page.title, target, {language}); + const redirectHTML = generateRedirectHTML(title, target, {language}); response.end(redirectHTML); diff --git a/src/write/build-modes/static-build.js b/src/write/build-modes/static-build.js index dc2bb2c..4f07405 100644 --- a/src/write/build-modes/static-build.js +++ b/src/write/build-modes/static-build.js @@ -355,10 +355,8 @@ export async function go({ }); }), - ...redirectWrites.map(({fromPath, toPath, title: titleFn}) => () => { - const title = titleFn({ - language, - }); + ...redirectWrites.map(({fromPath, toPath, title, getTitle}) => () => { + title ??= getTitle?.({language}); const to = getURLsFrom({ baseDirectory, -- cgit 1.3.0-6-gf8a5