-
Notifications
You must be signed in to change notification settings - Fork 3
/
index-generator.js
82 lines (72 loc) · 2.46 KB
/
index-generator.js
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const fs = require("fs");
const indexFilePrefix = "dist/genshin-wishes/";
const indexFilePath = "dist/genshin-wishes/index.template";
const indexFileProfilePath = "dist/genshin-wishes/index_profile.html";
const i18n = require("genshin-wishes-i18n/i18n/i18n.json");
console.log("After build script started...");
// read our index file
console.log("About to rewrite file: ", indexFilePath);
fs.readFile(indexFilePath, "utf8", function (err, data) {
if (err) {
return console.log(err);
}
data = data.replace(
/<!-- @@LANG_TAGS@@ -->/g,
i18n
.map(
(locale) =>
` <link rel="alternate" href="https://genshin-wishes.com/${locale.toLowerCase()}" hreflang="${locale.toLowerCase()}" />\n <link rel="alternate" href="https://genshin-wishes.com/${locale.toLowerCase()}" hreflang="${
locale.toLowerCase().split("-")[0]
}" />`
)
.join("\n")
);
// now write that file back
fs.writeFile(
indexFileProfilePath,
data
.replace(/@@LANG@@/g, "en")
.replace(/@@URL@@/g, "__url__")
.replace(/@@TITLE@@/g, "Genshin Wishes")
.replace(/@@DESCRIPTION@@/g, "genshin-wishes.com")
.replace(/@@IMAGE@@/g, "__host__/og/__profileId__.png"),
function (err) {
if (err) return console.log(err);
console.log("Successfully rewrote index_profile.html");
}
);
i18n.forEach((locale) => {
const translations = require("genshin-wishes-i18n/i18n/" +
locale +
"/site.json");
const title = translations.app.titleWithPage.replace(
"{{ page }}",
translations.app.description
);
const description = translations.landing.hero.subtitle;
const lowerCaseLocale = locale.toLowerCase();
fs.writeFileSync(
indexFilePrefix + "index_" + lowerCaseLocale + ".html",
data
.replace(/@@LANG@@/g, lowerCaseLocale)
.replace(/@@URL@@/g, "https://genshin-wishes.com")
.replace(/@@TITLE@@/g, title)
.replace(/@@DESCRIPTION@@/g, description)
.replace(
/@@IMAGE@@/g,
"https://genshin-wishes.com/assets/landing-landscape.jpg"
),
function (err) {
if (err) return console.log(err);
console.log("Successfully rewrote index_" + lowerCaseLocale + ".html");
}
);
});
const enUs = Buffer.from(
fs.readFileSync(indexFilePrefix + "index_en-us.html")
).toString();
fs.writeFileSync(
indexFilePrefix + "index.html",
enUs.replace('lang="en-us"', 'lang=""')
);
});