Skip to content

Commit

Permalink
fix: Update sitemap to include thoughts, and use actual modified date…
Browse files Browse the repository at this point in the history
…s of base pages
  • Loading branch information
ripixel committed Jun 6, 2020
1 parent 6aa729a commit 0f5a990
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"dev": "nodemon",
"build": "mkdir -p ./public && npm run build:css && npm run build:favicons && npm run build:pages && npm run build:images && npm run build:sitemap && npm run build:thoughts",
"build": "mkdir -p ./public && npm run build:css && npm run build:favicons && npm run build:pages && npm run build:images && npm run build:thoughts && npm run build:sitemap",
"build:dev": "mkdir -p ./public && npm run build:css && npm run build:pages && npm run build:images && npm run build:thoughts",
"build:pages": "ts-node ./scripts/generatePages",
"build:css": "cleancss -o ./public/styles.min.css ./assets/styles/*.css",
Expand Down
43 changes: 39 additions & 4 deletions scripts/generateSitemap.ts
Expand Up @@ -7,15 +7,50 @@ const SITE_ROOT = "https://www.ripixel.co.uk/";

console.log("/// Beginning sitemap generation");

const generatedPages = findInDir("./public", ".html")
const generatedPagesLocations = findInDir("./public", ".html");
const generatedPages = generatedPagesLocations
.filter((page) => page !== "public/404.html" && page !== "public/index.html")
.map((page) => page.replace("public/", "").replace(".html", ""));

const pagesModifiedDates: {
[key: string]: Date;
} = {};

const templatePagesLocations = findInDir("./pages", ".html");
const thoughtsPagesLocations = findInDir("./thoughts/articles", ".md");

templatePagesLocations.forEach((pageLocation) => {
pagesModifiedDates[
SITE_ROOT +
pageLocation
.replace("pages/", "")
.replace(".html", "")
.replace("index", "")
] = fs.statSync(pageLocation).mtime;
});

thoughtsPagesLocations.forEach((pageLocation) => {
pagesModifiedDates[
SITE_ROOT + pageLocation.replace("articles/", "").replace(".md", "")
] = fs.statSync(pageLocation).mtime;
});

console.log(
`Found ${generatedPages.length} public pages (not including index or 404)`
);

const generateUrlElement = (loc: string) => {
let changefreq = loc === SITE_ROOT ? "monthly" : "weekly";
let prio = loc === SITE_ROOT ? "1.0" : "0.8";

if (loc.indexOf("thoughts/") > -1) {
// is an article/subpage
prio = "0.5";
changefreq = "yearly";
}

console.log(loc, prio, changefreq);

return {
type: "element",
name: "url",
Expand All @@ -36,7 +71,7 @@ const generateUrlElement = (loc: string) => {
elements: [
{
type: "text",
text: new Date().toISOString().split("T")[0],
text: pagesModifiedDates[loc].toISOString().split("T")[0],
},
],
},
Expand All @@ -46,7 +81,7 @@ const generateUrlElement = (loc: string) => {
elements: [
{
type: "text",
text: loc === SITE_ROOT ? "monthly" : "weekly",
text: changefreq,
},
],
},
Expand All @@ -56,7 +91,7 @@ const generateUrlElement = (loc: string) => {
elements: [
{
type: "text",
text: loc === SITE_ROOT ? "1.0" : "0.5",
text: prio,
},
],
},
Expand Down

0 comments on commit 0f5a990

Please sign in to comment.