« get me outta code hell

common-templates.js « write « src - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/write/common-templates.js
blob: c9824a482ac3560bb7d9bee3d9ffe19bf7a177a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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)),
  });
}