-
Notifications
You must be signed in to change notification settings - Fork 1
/
static-page-plugin.ts
65 lines (62 loc) · 2.19 KB
/
static-page-plugin.ts
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
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
import { join as pathJoin, resolve as pathResolve } from "path";
import { streamToPromise, SitemapStream } from "sitemap";
import { PluginOption } from "vite";
import networkList from "./src/networks/networks";
const StaticNetworkPages = (): PluginOption => {
const name = "StaticNetworkPages";
const outDir = "dist";
const subDir = "networks";
const src = pathJoin(outDir, "index.html");
const MAIN_INFO = {
title: "Enkrypt: Ethereum, Polkadot and Bitcoin Wallet",
description:
"A multichain crypto wallet Hold, buy, send, receive, and swap tokens. Manage your NFTs. Access web3 apps across multiple blockchains.",
};
return {
name,
transformIndexHtml(html) {
html = html.replaceAll("##TITLE##", MAIN_INFO.title);
html = html.replaceAll("##DESCRIPTION##", MAIN_INFO.description);
return html;
},
closeBundle: () => {
const routes = Object.values(networkList);
const sitemap = new SitemapStream({
hostname: "https://www.enkrypt.com",
});
sitemap.write({
url: ``,
changefreq: "weekly",
priority: 1.0,
});
routes.forEach((p) => {
const finalDir = `${p.path}-wallet`;
const dir = pathResolve(outDir, subDir, finalDir);
if (!existsSync(dir)) {
mkdirSync(dir, { recursive: true });
}
const dst = pathJoin(outDir, subDir, finalDir, "index.html");
let indexFile = readFileSync(src, "utf-8");
indexFile = indexFile.replaceAll(MAIN_INFO.title, p.pageTitle);
indexFile = indexFile.replaceAll(MAIN_INFO.title, p.pageTitle);
indexFile = indexFile.replaceAll(
MAIN_INFO.description,
p.pageDescription
);
writeFileSync(dst, indexFile);
sitemap.write({
url: `/networks/${p.path}-wallet/`,
changefreq: "weekly",
priority: 1.0,
});
console.log(`${name}: Saved ${src} to ${dst}`);
});
sitemap.end();
streamToPromise(sitemap).then((buffer) =>
writeFileSync(pathResolve(outDir, "sitemap.xml"), buffer)
);
},
};
};
export { StaticNetworkPages };