-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsitemap.js
More file actions
27 lines (22 loc) · 861 Bytes
/
sitemap.js
File metadata and controls
27 lines (22 loc) · 861 Bytes
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
const {SitemapStream, XMLToSitemapItemStream} = require("sitemap");
const nodeFs = require("fs");
const path = require("path");
const codes = require("./src/server/codes.json");
/**
* generate sitemap.xml
*/
const createSitemap = () => {
const sitemap = new SitemapStream({hostname: "https://pengfeiw.github.io"});
const writeStream = nodeFs.createWriteStream(path.join(__dirname, "./public/sitemap.xml"));
sitemap.pipe(writeStream);
// home
sitemap.write({url: "/", changefreq: "monthly", priority: 1});
// hellolinearalgebra home
sitemap.write({url: "/minicode", changefreq: "monthly", priority: 0.9});
for (let i = 0; i < codes.length; i++) {
// codes
sitemap.write({url: `/minicode/${codes[i].path}`, changefreq: "weekly", priority: 0.8});
}
sitemap.end();
};
module.exports = {createSitemap};