Skip to content

Commit

Permalink
🔍 add working sitemap for indexnow
Browse files Browse the repository at this point in the history
  • Loading branch information
scottnath committed Apr 26, 2024
1 parent f669f63 commit 1fa6d8b
Show file tree
Hide file tree
Showing 8 changed files with 189 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/IndexNow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
122 changes: 112 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions workspaces/website/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion workspaces/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": {
Expand Down
4 changes: 1 addition & 3 deletions workspaces/website/src/components/BaseHead.astro
Original file line number Diff line number Diff line change
@@ -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 <BaseHead /> 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;
Expand Down
72 changes: 72 additions & 0 deletions workspaces/website/src/pages/sitemap-index.xml.ts
Original file line number Diff line number Diff line change
@@ -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',
},
})
}
2 changes: 1 addition & 1 deletion workspaces/website/src/pages/whoami.mdx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
11 changes: 0 additions & 11 deletions workspaces/website/src/pwa.js

This file was deleted.

0 comments on commit 1fa6d8b

Please sign in to comment.