-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
189 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.