diff --git a/site/netlify/edge-functions/trailing-slash.ts b/site/netlify/edge-functions/trailing-slash.ts new file mode 100644 index 00000000..d2807552 --- /dev/null +++ b/site/netlify/edge-functions/trailing-slash.ts @@ -0,0 +1,21 @@ +import type { Config } from '@netlify/edge-functions'; + +export default async (request: Request) => { + const url = new URL(request.url); + const redirectUrl = new URL(url.pathname.replace(/\/$/, ''), url.origin); + redirectUrl.search = url.search; + redirectUrl.hash = url.hash; + + return new Response(null, { + status: 301, + headers: { + location: redirectUrl.toString(), + 'cache-control': 'public, max-age=86400', + }, + }); +}; + +export const config: Config = { + cache: 'manual', + pattern: '.+/$', +}; diff --git a/site/src/pages/rss.xml.js b/site/src/pages/rss.xml.js index 204f5594..76f05ce4 100644 --- a/site/src/pages/rss.xml.js +++ b/site/src/pages/rss.xml.js @@ -9,9 +9,10 @@ export async function GET(context) { title: SITE_TITLE, description: SITE_DESCRIPTION, site: context.site, + trailingSlash: false, items: posts.map((post) => ({ ...post.data, - link: `/blog/${post.id}/`, + link: `/blog/${post.id}`, })), }); }