mirror of
https://github.com/zoriya/v10.git
synced 2026-08-12 17:09:55 +00:00
fix(site): redirect trailing-slash URLs via edge function (#885)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
7eac2bc3a1
commit
20406a024e
@@ -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: '.+/$',
|
||||
};
|
||||
@@ -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}`,
|
||||
})),
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user