« 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: 2dd4c924172bf52aed0b635ff78fc1b37d2396c7 (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
import * as html from '#html';

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 generateGlobalWikiDataJSON({
  serializeThings,
  wikiData,
}) {
  const stringifyThings = thingData =>
    JSON.stringify(serializeThings(thingData));

  return '{\n' +
    ([
      `"albumData": ${stringifyThings(wikiData.albumData)},`,
      wikiData.wikiInfo.enableFlashesAndGames &&
        `"flashData": ${stringifyThings(wikiData.flashData)},`,
      `"artistData": ${stringifyThings(wikiData.artistData)}`,
    ]
      .filter(Boolean)
      .map(line => '  ' + line)
      .join('\n')) +
    '\n}';
}