@@ -2,27 +2,26 @@ import rss, { pagesGlobToRssItems } from '@astrojs/rss';
22import { SITE_TITLE , SITE_DESCRIPTION } from '../consts' ;
33
44export async function GET ( context ) {
5- // Get the raw site URL from context (ensure it's a string) and remove any trailing slash.
5+ // Ensure context. site is a string and remove any trailing slash.
66 const rawSite = typeof context . site === 'string' ? context . site : context . site . href ;
77 const trimmedSite = rawSite . replace ( / \/ $ / , '' ) ;
8-
9- // Our configured base path from astro.config.mjs
108 const basePath = '/cookbook/' ;
11- // Construct the full site URL (e.g., "https://nicholasdbrady.github.io/cookbook/")
9+ // Construct the full site URL: "https://nicholasdbrady.github.io/cookbook/"
1210 const fullSiteUrl = trimmedSite + basePath ;
1311
14- // Use pagesGlobToRssItems() to automatically generate RSS items from your blog pages.
15- // This assumes your published blog pages live in src/pages/blog/.
16- let items = await pagesGlobToRssItems ( import . meta. glob ( './blog/*.{astro,md,mdx}' ) ) ;
12+ // Use a glob pattern array to include only blog pages and exclude the dynamic route file.
13+ let items = await pagesGlobToRssItems (
14+ import . meta. glob ( [
15+ './blog/*.{astro,md,mdx}' ,
16+ '!./blog/[...slug].astro'
17+ ] )
18+ ) ;
1719
18- // Filter out the dynamic route file (i.e. [...slug].astro) which doesn't have its own frontmatter.
19- items = items . filter ( item => ! item . file . includes ( '[...slug]' ) ) ;
20-
21- // Post-process each item so that its link and guid are built from the fullSiteUrl.
20+ // Post-process each item so that its link and guid are built correctly.
2221 items = items . map ( item => {
23- // Remove any leading slash from the item.link ( if present)
22+ // Remove a leading slash from the item.link if present.
2423 const relativePath = item . link . startsWith ( '/' ) ? item . link . substring ( 1 ) : item . link ;
25- // Build the final URL using fullSiteUrl as the base.
24+ // Construct the fixed link using the fullSiteUrl as the base.
2625 const fixedLink = new URL ( relativePath , fullSiteUrl ) . href ;
2726 return {
2827 ...item ,
@@ -32,11 +31,11 @@ export async function GET(context) {
3231 } ) ;
3332
3433 return rss ( {
35- title : SITE_TITLE , // Your feed title
36- description : SITE_DESCRIPTION , // Your feed description
37- site : fullSiteUrl , // Ensures the channel <link> includes the base path
38- items, // The list of RSS items with full HTML content
39- trailingSlash : true ,
40- customData : `<language>en-us</language>` , // Optional extra XML data
34+ title : SITE_TITLE ,
35+ description : SITE_DESCRIPTION ,
36+ site : fullSiteUrl , // Ensures the channel <link> includes the "/cookbook/" base.
37+ items,
38+ trailingSlash : true , // Matches your astro.config.mjs trailingSlash: "always"
39+ customData : `<language>en-us</language>` ,
4140 } ) ;
4241}
0 commit comments