diff options
Diffstat (limited to 'src/write/common-templates.js')
-rw-r--r-- | src/write/common-templates.js | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/write/common-templates.js b/src/write/common-templates.js new file mode 100644 index 0000000..c9824a4 --- /dev/null +++ b/src/write/common-templates.js @@ -0,0 +1,57 @@ +import * as html from '#html'; +import {getArtistNumContributions} from '#wiki-data'; + +export function generateRedirectHTML(title, target, {language}) { + return `<!DOCTYPE html>\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 function generateRandomLinkDataJSON({wikiData}) { + const {albumData, artistData} = wikiData; + + return JSON.stringify({ + albumDirectories: + albumData + .map(album => album.directory), + + albumTrackDirectories: + albumData + .map(album => album.tracks + .map(track => track.directory)), + + artistDirectories: + artistData + .filter(artist => !artist.isAlias) + .map(artist => artist.directory), + + artistNumContributions: + artistData + .filter(artist => !artist.isAlias) + .map(artist => getArtistNumContributions(artist)), + }); +} |