From 1fa6d8bdf06cf4dc7de2792bbdc10ed9dbdcec54 Mon Sep 17 00:00:00 2001 From: Scott Nath Date: Fri, 26 Apr 2024 13:49:35 -0400 Subject: [PATCH] :mag: add working sitemap for indexnow --- .github/workflows/IndexNow.yml | 2 +- package-lock.json | 122 ++++++++++++++++-- workspaces/website/astro.config.mjs | 3 +- workspaces/website/package.json | 2 +- .../website/src/components/BaseHead.astro | 4 +- .../website/src/pages/sitemap-index.xml.ts | 72 +++++++++++ workspaces/website/src/pages/whoami.mdx | 2 +- workspaces/website/src/pwa.js | 11 -- 8 files changed, 189 insertions(+), 29 deletions(-) create mode 100644 workspaces/website/src/pages/sitemap-index.xml.ts delete mode 100644 workspaces/website/src/pwa.js diff --git a/.github/workflows/IndexNow.yml b/.github/workflows/IndexNow.yml index d121192..af32d66 100644 --- a/.github/workflows/IndexNow.yml +++ b/.github/workflows/IndexNow.yml @@ -11,7 +11,7 @@ jobs: - name: indexnow-action uses: bojieyang/indexnow-action@v2 with: - sitemap-location: 'https://scottnath.com/rss.xml' + sitemap-location: 'https://scottnath.com/sitemap-index.xml' since: 1 since-unit: "year" key: ${{ secrets.INDEXNOW_KEY }} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 8d850c4..c50449d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -323,15 +323,6 @@ "kleur": "^4.1.5" } }, - "node_modules/@astrojs/sitemap": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/@astrojs/sitemap/-/sitemap-3.1.2.tgz", - "integrity": "sha512-FxOJldIl5ltZ5CNjocQxHkAO9orwHBjqtaU28o4smobp9vowS0nbGp+I9CrPxkzWdl1crSDm9vjL9tnvG1DSug==", - "dependencies": { - "sitemap": "^7.1.1", - "zod": "^3.22.4" - } - }, "node_modules/@astrojs/telemetry": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/@astrojs/telemetry/-/telemetry-3.0.4.tgz", @@ -25315,6 +25306,18 @@ "integrity": "sha512-uHaJFihxmJcEX3kT4I23ABqKKalJ/zDrDg0lsFtc1h+3uw49SIJ5beyhx5ExVRti3AvKoOJngIj7xz3oylPdWQ==", "dev": true }, + "node_modules/lodash.get": { + "version": "4.4.2", + "resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz", + "integrity": "sha512-z+Uw/vLuy6gQe8cfaFWD7p0wVv8fJl3mbzXh33RS+0oW2wvUqiRXiQ69gLWSLpgB5/6sU+r6BlQR0MBILadqTQ==", + "dev": true + }, + "node_modules/lodash.isequal": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz", + "integrity": "sha512-pDo3lu8Jhfjqls6GkMgpahsF9kCyayhgykjyLMNFTKWrpVdAQtYyB4muAMWozBB4ig/dtWAmsMxLEI8wuz+DYQ==", + "dev": true + }, "node_modules/lodash.ismatch": { "version": "4.4.0", "resolved": "https://registry.npmjs.org/lodash.ismatch/-/lodash.ismatch-4.4.0.tgz", @@ -26872,6 +26875,15 @@ "node": ">=0.10.0" } }, + "node_modules/mri": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/mri/-/mri-1.2.0.tgz", + "integrity": "sha512-tzzskb3bG8LvYGFF/mDTpq3jpI6Q9wc3LEmBaghu+DdCssd1FakN7Bc0hVNmEyGq1bq3RgfkCb3cmQLpNPOroA==", + "dev": true, + "engines": { + "node": ">=4" + } + }, "node_modules/mrmime": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/mrmime/-/mrmime-1.0.1.tgz", @@ -32954,6 +32966,35 @@ "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==" }, + "node_modules/resume-schema": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/resume-schema/-/resume-schema-1.0.0.tgz", + "integrity": "sha512-9ZEP3oO1IRrjQWTOfDq7fDNNeJp7gWqfS/l2D02f6f25nRw/wRAkpDyvIlw9uoaDARK7Ebj/CN2D/6Ht27S0zg==", + "dev": true, + "dependencies": { + "z-schema": "^4.2.2" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/resumed": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/resumed/-/resumed-3.0.1.tgz", + "integrity": "sha512-bHv7qDQwmx5ei+u81JIxD1Cdcm/d6wcJXzmi7rMiGttC8kV7jnznBeN0QpYi6xy6vl51VuokTatAhXXfbo4G9w==", + "dev": true, + "dependencies": { + "resume-schema": "^1.0.0", + "sade": "^1.7.0", + "yoctocolors": "^1.0.0" + }, + "bin": { + "resumed": "bin/resumed.js" + }, + "engines": { + "node": ">=14.16" + } + }, "node_modules/retext": { "version": "8.1.0", "resolved": "https://registry.npmjs.org/retext/-/retext-8.1.0.tgz", @@ -33440,6 +33481,18 @@ "tslib": "^2.1.0" } }, + "node_modules/sade": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/sade/-/sade-1.8.1.tgz", + "integrity": "sha512-xal3CZX1Xlo/k4ApwCFrHVACi9fBqJ7V+mwhBsuf/1IOKbBy098Fex+Wa/5QMubw09pSZ/u8EY8PWgevJsXp1A==", + "dev": true, + "dependencies": { + "mri": "^1.1.0" + }, + "engines": { + "node": ">=6" + } + }, "node_modules/safe-array-concat": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/safe-array-concat/-/safe-array-concat-1.1.2.tgz", @@ -38150,6 +38203,15 @@ "spdx-expression-parse": "^3.0.0" } }, + "node_modules/validator": { + "version": "13.11.0", + "resolved": "https://registry.npmjs.org/validator/-/validator-13.11.0.tgz", + "integrity": "sha512-Ii+sehpSfZy+At5nPdnyMhx78fEoPDkR2XW/zimHEL3MyGJQOCQ7WeP20jPYRz7ZCpcKLB21NxuXHF3bxjStBQ==", + "dev": true, + "engines": { + "node": ">= 0.10" + } + }, "node_modules/vary": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", @@ -39490,6 +39552,45 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/yoctocolors": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/yoctocolors/-/yoctocolors-1.0.0.tgz", + "integrity": "sha512-qJNAmSF77lWjfRVwCZK3PcKYWrr+55RUQTiXDxXHGbxzf8WuuRgftIB3hqZ5fykjOF/MC62cazsG/2ZDBedOnQ==", + "dev": true, + "engines": { + "node": ">=14.16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/z-schema": { + "version": "4.2.4", + "resolved": "https://registry.npmjs.org/z-schema/-/z-schema-4.2.4.tgz", + "integrity": "sha512-YvBeW5RGNeNzKOUJs3rTL4+9rpcvHXt5I051FJbOcitV8bl40pEfcG0Q+dWSwS0/BIYrMZ/9HHoqLllMkFhD0w==", + "dev": true, + "dependencies": { + "lodash.get": "^4.4.2", + "lodash.isequal": "^4.5.0", + "validator": "^13.6.0" + }, + "bin": { + "z-schema": "bin/z-schema" + }, + "engines": { + "node": ">=6.0.0" + }, + "optionalDependencies": { + "commander": "^2.7.1" + } + }, + "node_modules/z-schema/node_modules/commander": { + "version": "2.20.3", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", + "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", + "dev": true, + "optional": true + }, "node_modules/zod": { "version": "3.22.4", "resolved": "https://registry.npmjs.org/zod/-/zod-3.22.4.tgz", @@ -39531,7 +39632,6 @@ "@astrojs/mdx": "^2.2.4", "@astrojs/react": "^3.2.0", "@astrojs/rss": "^4.0.5", - "@astrojs/sitemap": "^3.1.2", "@types/react": "^18.2.75", "@types/react-dom": "^18.2.24", "airtable": "^0.12.2", @@ -39540,6 +39640,7 @@ "profile-components": "^0.4.1", "react": "^18.2.0", "react-dom": "^18.2.0", + "sitemap": "^7.1.1", "typescript": "^5.4.5" }, "devDependencies": { @@ -39552,6 +39653,7 @@ "lit": "^3.1.2", "postcss-nested": "^6.0.1", "prop-types": "^15.8.1", + "resumed": "^3.0.1", "sass": "^1.74.1", "vite": "^5.2.8" } diff --git a/workspaces/website/astro.config.mjs b/workspaces/website/astro.config.mjs index b811fd8..8d5fc31 100644 --- a/workspaces/website/astro.config.mjs +++ b/workspaces/website/astro.config.mjs @@ -3,7 +3,6 @@ import mdx from '@astrojs/mdx'; import partytown from '@astrojs/partytown'; import react from '@astrojs/react'; import lit from '@astrojs/lit'; -import sitemap from '@astrojs/sitemap'; // https://astro.build/config export default defineConfig({ @@ -19,7 +18,7 @@ export default defineConfig({ '/about': '/whoami', }, site: 'https://scottnath.com', - integrations: [lit(), mdx(), sitemap(), react(), + integrations: [lit(), mdx(), react(), partytown({ // Adds dataLayer.push as a forwarding-event. config: { diff --git a/workspaces/website/package.json b/workspaces/website/package.json index 0b2b831..9275864 100644 --- a/workspaces/website/package.json +++ b/workspaces/website/package.json @@ -16,7 +16,6 @@ "@astrojs/mdx": "^2.2.4", "@astrojs/react": "^3.2.0", "@astrojs/rss": "^4.0.5", - "@astrojs/sitemap": "^3.1.2", "@types/react": "^18.2.75", "@types/react-dom": "^18.2.24", "airtable": "^0.12.2", @@ -25,6 +24,7 @@ "profile-components": "^0.4.1", "react": "^18.2.0", "react-dom": "^18.2.0", + "sitemap": "^7.1.1", "typescript": "^5.4.5" }, "devDependencies": { diff --git a/workspaces/website/src/components/BaseHead.astro b/workspaces/website/src/components/BaseHead.astro index ccc40e0..f633018 100644 --- a/workspaces/website/src/components/BaseHead.astro +++ b/workspaces/website/src/components/BaseHead.astro @@ -1,11 +1,9 @@ --- -import { pwaInfo } from 'virtual:pwa-info'; -import { pwaAssetsHead } from 'virtual:pwa-assets/head'; // Import the global.css file here so that it is included on // all pages through the use of the component. import '../styles/global.css'; import '../components/resume/styles/resume.css'; -import { PROFILE_PIC, SITE_TITLE, SITE_DESCRIPTION, BLAHG } from '../consts'; +import { PROFILE_PIC, BLAHG } from '../consts'; export interface Props { title: string; diff --git a/workspaces/website/src/pages/sitemap-index.xml.ts b/workspaces/website/src/pages/sitemap-index.xml.ts new file mode 100644 index 0000000..7716226 --- /dev/null +++ b/workspaces/website/src/pages/sitemap-index.xml.ts @@ -0,0 +1,72 @@ +import { getCollection } from 'astro:content'; +import { SitemapStream, streamToPromise } from 'sitemap'; + +const posts = (await getCollection('blahg')).sort( + (a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf() +); + +/** + * @todo automate these using git lastmodified + * @see https://github.com/eligundry/eligundry.com/blob/00b6898c39c910fa252a92dc6cf869440d531857/src/lib/lastModified.ts + */ +const sitepages = [ + { + url: 'https://scottnath.com', + updatedDate: new Date(), + }, + { + url: 'https://scottnath.com/whoami', + updatedDate: new Date('2024-04-24'), + }, + { + url: 'https://scottnath.com/resume', + updatedDate: new Date('2024-04-26'), + }, + { + url: 'https://scottnath.com/blahg', + updatedDate: new Date('2024-04-01'), + } +]; + +export async function GET() { + // Create a stream to write to + const stream = new SitemapStream({ + hostname: 'https://scottnath.com' + }); + + await Promise.all( + sitepages.map(async ({url, updatedDate}) => { + const lastmod = new Date(updatedDate).toISOString(); + stream.write({ + url, + lastmod, + changefreq: 'daily', + priority: 0.7, + }) + }) + ) + + await Promise.all( + posts.map(async (post) => { + const url = `/${post.collection}/${post.slug}/` + const lastmodDate = post.data.updatedDate || post.data.pubDate; + const lastmod = new Date(lastmodDate).toISOString(); + stream.write({ + url, + lastmod, + changefreq: 'daily', + priority: 0.7, + }) + }) + ) + + stream.end() + + const sitemap = await streamToPromise(stream) + return new Response(sitemap, { + status: 200, + headers: { + 'Content-Type': 'text/xml', + }, + }) +} \ No newline at end of file diff --git a/workspaces/website/src/pages/whoami.mdx b/workspaces/website/src/pages/whoami.mdx index 4caa54e..b9dad01 100644 --- a/workspaces/website/src/pages/whoami.mdx +++ b/workspaces/website/src/pages/whoami.mdx @@ -1,7 +1,7 @@ --- title: 'Scott Nath: What about him? Who is he? What does he do?' pubDate: "2024-04-04" -updatedDate: "2024-04-11" +updatedDate: "2024-04-24" --- import SiteWide from '~layouts/SiteWide.astro'; diff --git a/workspaces/website/src/pwa.js b/workspaces/website/src/pwa.js deleted file mode 100644 index 7ff1ba6..0000000 --- a/workspaces/website/src/pwa.js +++ /dev/null @@ -1,11 +0,0 @@ -import { registerSW } from 'virtual:pwa-register' - -registerSW({ - immediate: true, - onRegisteredSW(swScriptUrl) { - console.log('SW registered: ', swScriptUrl) - }, - onOfflineReady() { - console.log('PWA application ready to work offline') - }, -})