feat: improve sitemap
This commit is contained in:
parent
085bffee88
commit
943e1ad4cf
6 changed files with 87 additions and 20 deletions
|
@ -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
|
||||
};
|
||||
}
|
4
package-lock.json
generated
4
package-lock.json
generated
|
@ -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",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "www-aaronjy-2024",
|
||||
"version": "1.5.0.0",
|
||||
"version": "1.6.0.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
|
||||
<url><loc>https://www.aaronjy.me/</loc><lastmod>2025-03-20T20:04:24.356Z</lastmod><changefreq>weekly</changefreq><priority>0.7</priority></url>
|
||||
<url><loc>https://www.aaronjy.me/about/</loc><lastmod>2025-03-20T20:04:24.356Z</lastmod><changefreq>weekly</changefreq><priority>0.7</priority></url>
|
||||
<url><loc>https://www.aaronjy.me/cv/</loc><lastmod>2025-03-20T20:04:24.356Z</lastmod><changefreq>weekly</changefreq><priority>0.7</priority></url>
|
||||
<url><loc>https://www.aaronjy.me/tags/</loc><lastmod>2025-03-20T20:04:24.356Z</lastmod><changefreq>weekly</changefreq><priority>0.7</priority></url>
|
||||
<url><loc>https://www.aaronjy.me/writing/</loc><lastmod>2025-03-20T20:04:24.356Z</lastmod><changefreq>weekly</changefreq><priority>0.7</priority></url>
|
||||
<url><loc>https://www.aaronjy.me/writing/attitudes-to-reading/</loc><lastmod>2025-03-20T20:04:24.356Z</lastmod><changefreq>weekly</changefreq><priority>0.7</priority></url>
|
||||
<url><loc>https://www.aaronjy.me/writing/moving-from-github-to-forgejo/</loc><lastmod>2025-03-20T20:04:24.356Z</lastmod><changefreq>weekly</changefreq><priority>0.7</priority></url>
|
||||
<url><loc>https://www.aaronjy.me/writing/performance-considerations-tcp-game-server/</loc><lastmod>2025-03-20T20:04:24.356Z</lastmod><changefreq>weekly</changefreq><priority>0.7</priority></url>
|
||||
<url><loc>https://www.aaronjy.me/writing/quick-reflection-katherine-may/</loc><lastmod>2025-03-20T20:04:24.356Z</lastmod><changefreq>weekly</changefreq><priority>0.7</priority></url>
|
||||
<url><loc>https://www.aaronjy.me/writing/static-site-on-google-cloud/</loc><lastmod>2025-03-20T20:04:24.356Z</lastmod><changefreq>weekly</changefreq><priority>0.7</priority></url>
|
||||
<url><loc>https://www.aaronjy.me/writing/support-content-filte-structure-changes-on-a-static-site/</loc><lastmod>2025-03-20T20:04:24.356Z</lastmod><changefreq>weekly</changefreq><priority>0.7</priority></url>
|
||||
<url><loc>https://www.aaronjy.me/</loc><priority>1</priority></url>
|
||||
<url><loc>https://www.aaronjy.me/about/</loc><priority>0.8</priority></url>
|
||||
<url><loc>https://www.aaronjy.me/cv/</loc><priority>0.8</priority></url>
|
||||
<url><loc>https://www.aaronjy.me/tags/</loc><priority>0.8</priority></url>
|
||||
<url><loc>https://www.aaronjy.me/writing/</loc><priority>0.8</priority></url>
|
||||
<url><loc>https://www.aaronjy.me/writing/attitudes-to-reading/</loc><priority>0.6</priority><pubdate>Tue, 18 Mar 2025 00:00:00 GMT</pubdate></url>
|
||||
<url><loc>https://www.aaronjy.me/writing/moving-from-github-to-forgejo/</loc><priority>0.6</priority><pubdate>Sun, 16 Mar 2025 00:00:00 GMT</pubdate></url>
|
||||
<url><loc>https://www.aaronjy.me/writing/performance-considerations-tcp-game-server/</loc><priority>0.6</priority><pubdate>Sun, 23 Feb 2025 21:12:37 GMT</pubdate></url>
|
||||
<url><loc>https://www.aaronjy.me/writing/quick-reflection-katherine-may/</loc><priority>0.6</priority><pubdate>Sun, 09 Mar 2025 00:00:00 GMT</pubdate></url>
|
||||
<url><loc>https://www.aaronjy.me/writing/static-site-on-google-cloud/</loc><priority>0.6</priority><pubdate>Wed, 01 May 2024 00:00:00 GMT</pubdate></url>
|
||||
<url><loc>https://www.aaronjy.me/writing/support-content-filte-structure-changes-on-a-static-site/</loc><priority>0.6</priority><pubdate>Mon, 18 Mar 2024 16:47:32 GMT</pubdate></url>
|
||||
</urlset>
|
|
@ -1,4 +1,14 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||
<sitemap><loc>https://www.aaronjy.me/sitemap-0.xml</loc></sitemap>
|
||||
</sitemapindex>
|
||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
|
||||
<url><loc>https://www.aaronjy.me/</loc><priority>1</priority></url>
|
||||
<url><loc>https://www.aaronjy.me/about/</loc><priority>0.8</priority></url>
|
||||
<url><loc>https://www.aaronjy.me/cv/</loc><priority>0.8</priority></url>
|
||||
<url><loc>https://www.aaronjy.me/tags/</loc><priority>0.8</priority></url>
|
||||
<url><loc>https://www.aaronjy.me/writing/</loc><priority>0.8</priority></url>
|
||||
<url><loc>https://www.aaronjy.me/writing/attitudes-to-reading/</loc><priority>0.6</priority><pubdate>2025-03-18T00:00:00.000Z</pubdate></url>
|
||||
<url><loc>https://www.aaronjy.me/writing/moving-from-github-to-forgejo/</loc><priority>0.6</priority><pubdate>2025-03-16T00:00:00.000Z</pubdate></url>
|
||||
<url><loc>https://www.aaronjy.me/writing/performance-considerations-tcp-game-server/</loc><priority>0.6</priority><pubdate>2025-02-23T21:12:37.864Z</pubdate></url>
|
||||
<url><loc>https://www.aaronjy.me/writing/quick-reflection-katherine-may/</loc><priority>0.6</priority><pubdate>2025-03-09T00:00:00.000Z</pubdate></url>
|
||||
<url><loc>https://www.aaronjy.me/writing/static-site-on-google-cloud/</loc><priority>0.6</priority><pubdate>2024-05-01T00:00:00.000Z</pubdate></url>
|
||||
<url><loc>https://www.aaronjy.me/writing/support-content-filte-structure-changes-on-a-static-site/</loc><priority>0.6</priority><pubdate>2024-03-18T16:47:32.150Z</pubdate></url>
|
||||
</urlset>
|
|
@ -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
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue