From 943e1ad4cf2aeebb48e3f394aa7aeaa6406eab61 Mon Sep 17 00:00:00 2001 From: Aaron Yarborough <3855819+AaronJY@users.noreply.github.com> Date: Fri, 21 Mar 2025 12:45:31 +0000 Subject: [PATCH] feat: improve sitemap --- next-sitemap.config.cjs | 57 +++++++++++++++++++++++++++++++++++++++++ package-lock.json | 4 +-- package.json | 2 +- public/sitemap-0.xml | 22 ++++++++-------- public/sitemap.xml | 16 +++++++++--- src/lib/content.js | 6 ++--- 6 files changed, 87 insertions(+), 20 deletions(-) diff --git a/next-sitemap.config.cjs b/next-sitemap.config.cjs index a4821bc..f98d6ea 100644 --- a/next-sitemap.config.cjs +++ b/next-sitemap.config.cjs @@ -1,8 +1,13 @@ +const fs = require('fs'), + fm = require('front-matter') + /** @type {import('next-sitemap').IConfig} */ module.exports = { siteUrl: process.env.SITE_URL || 'https://www.aaronjy.me', changefreq: 'weekly', generateRobotsTxt: true, + autoLastmod: false, + generateIndexSitemap: false, robotsTxtOptions: { policies: [ { @@ -10,5 +15,57 @@ module.exports = { allow: '/' } ] + }, + transform: async (config, path) => { + const metadata = { + loc: path + }; + + if (isHomepage(path)) { + metadata.priority = 1; + } else if (isBasePage(path)) { + metadata.priority = 0.8; + } else { + if (isArticle(path)) { + metadata.priority = 0.6; + const attributes = getArticleAttibutes(`content${path}.md`); + if (!attributes) + return null; + + metadata.pubdate = attributes.pubdate ?? null; + metadata.moddate = attributes.moddate ?? null; + + console.log("Calculated sitemap dates for article", path); + } + } + + return metadata; } } + +function isHomepage(path) { + return path === "/"; +} + +function isBasePage(path) { + return path.split("/").length === 2; +} + +function isArticle(path) { + return path.startsWith("/writing/"); +} + +function getArticleAttibutes(path) { + const fileContents = fs.readFileSync(path, { + encoding: 'utf-8' + }) + + // @ts-ignore + const { attributes } = fm(fileContents); + + return { + ...attributes, + pubdate: attributes.pubdate?.toISOString() ?? null, + moddate: attributes.moddate?.toISOString() ?? null + }; +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index ec0a147..a54aa15 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "www-aaronjy-2024", - "version": "1.3.0.0", + "version": "1.5.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "www-aaronjy-2024", - "version": "1.2.0.0", + "version": "1.5.0.0", "dependencies": { "@highlightjs/cdn-assets": "^11.11.1", "date-fns": "^4.1.0", diff --git a/package.json b/package.json index d1ce925..bed8abf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "www-aaronjy-2024", - "version": "1.5.0.0", + "version": "1.6.0.0", "private": true, "type": "module", "scripts": { diff --git a/public/sitemap-0.xml b/public/sitemap-0.xml index 4321453..5ddf8e5 100644 --- a/public/sitemap-0.xml +++ b/public/sitemap-0.xml @@ -1,14 +1,14 @@ -https://www.aaronjy.me/2025-03-20T20:04:24.356Zweekly0.7 -https://www.aaronjy.me/about/2025-03-20T20:04:24.356Zweekly0.7 -https://www.aaronjy.me/cv/2025-03-20T20:04:24.356Zweekly0.7 -https://www.aaronjy.me/tags/2025-03-20T20:04:24.356Zweekly0.7 -https://www.aaronjy.me/writing/2025-03-20T20:04:24.356Zweekly0.7 -https://www.aaronjy.me/writing/attitudes-to-reading/2025-03-20T20:04:24.356Zweekly0.7 -https://www.aaronjy.me/writing/moving-from-github-to-forgejo/2025-03-20T20:04:24.356Zweekly0.7 -https://www.aaronjy.me/writing/performance-considerations-tcp-game-server/2025-03-20T20:04:24.356Zweekly0.7 -https://www.aaronjy.me/writing/quick-reflection-katherine-may/2025-03-20T20:04:24.356Zweekly0.7 -https://www.aaronjy.me/writing/static-site-on-google-cloud/2025-03-20T20:04:24.356Zweekly0.7 -https://www.aaronjy.me/writing/support-content-filte-structure-changes-on-a-static-site/2025-03-20T20:04:24.356Zweekly0.7 +https://www.aaronjy.me/1 +https://www.aaronjy.me/about/0.8 +https://www.aaronjy.me/cv/0.8 +https://www.aaronjy.me/tags/0.8 +https://www.aaronjy.me/writing/0.8 +https://www.aaronjy.me/writing/attitudes-to-reading/0.6Tue, 18 Mar 2025 00:00:00 GMT +https://www.aaronjy.me/writing/moving-from-github-to-forgejo/0.6Sun, 16 Mar 2025 00:00:00 GMT +https://www.aaronjy.me/writing/performance-considerations-tcp-game-server/0.6Sun, 23 Feb 2025 21:12:37 GMT +https://www.aaronjy.me/writing/quick-reflection-katherine-may/0.6Sun, 09 Mar 2025 00:00:00 GMT +https://www.aaronjy.me/writing/static-site-on-google-cloud/0.6Wed, 01 May 2024 00:00:00 GMT +https://www.aaronjy.me/writing/support-content-filte-structure-changes-on-a-static-site/0.6Mon, 18 Mar 2024 16:47:32 GMT \ No newline at end of file diff --git a/public/sitemap.xml b/public/sitemap.xml index 02435d6..ac863e1 100644 --- a/public/sitemap.xml +++ b/public/sitemap.xml @@ -1,4 +1,14 @@ - -https://www.aaronjy.me/sitemap-0.xml - \ No newline at end of file + +https://www.aaronjy.me/1 +https://www.aaronjy.me/about/0.8 +https://www.aaronjy.me/cv/0.8 +https://www.aaronjy.me/tags/0.8 +https://www.aaronjy.me/writing/0.8 +https://www.aaronjy.me/writing/attitudes-to-reading/0.62025-03-18T00:00:00.000Z +https://www.aaronjy.me/writing/moving-from-github-to-forgejo/0.62025-03-16T00:00:00.000Z +https://www.aaronjy.me/writing/performance-considerations-tcp-game-server/0.62025-02-23T21:12:37.864Z +https://www.aaronjy.me/writing/quick-reflection-katherine-may/0.62025-03-09T00:00:00.000Z +https://www.aaronjy.me/writing/static-site-on-google-cloud/0.62024-05-01T00:00:00.000Z +https://www.aaronjy.me/writing/support-content-filte-structure-changes-on-a-static-site/0.62024-03-18T16:47:32.150Z + \ No newline at end of file diff --git a/src/lib/content.js b/src/lib/content.js index 5be6721..8cafce5 100644 --- a/src/lib/content.js +++ b/src/lib/content.js @@ -21,8 +21,8 @@ export function getMarkdownEntry (path) { return { attributes: { ...attributes, - pubdate: attributes.pubdate?.toUTCString() ?? null - + pubdate: attributes.pubdate?.toUTCString() ?? null, + moddate: attributes.moddate?.toUTCString() ?? null }, html, slug @@ -76,4 +76,4 @@ export function getContentTags (contentPath) { } return allTags -} +} \ No newline at end of file