From a74ff62415ff20388ff247f3a9fc22afcd1ad942 Mon Sep 17 00:00:00 2001 From: Samuel Colvin Date: Wed, 26 Mar 2025 09:40:16 +0000 Subject: [PATCH 1/3] use hyphen in docs --- docs-site/src/index.ts | 13 +++++++++++++ docs/{common_tools.md => common-tools.md} | 0 mkdocs.yml | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) rename docs/{common_tools.md => common-tools.md} (100%) diff --git a/docs-site/src/index.ts b/docs-site/src/index.ts index b79ef923ad..d0fa3bc2b2 100644 --- a/docs-site/src/index.ts +++ b/docs-site/src/index.ts @@ -3,6 +3,11 @@ export default { const r = await env.ASSETS.fetch(request) if (r.status == 404) { const url = new URL(request.url) + const redirectPath = redirect(url.pathname) + if (redirectPath) { + url.pathname = redirectPath + return Response.redirect(url.toString(), 301) + } url.pathname = '/404.html' const r = await env.ASSETS.fetch(url) return new Response(r.body, { status: 404 }) @@ -10,3 +15,11 @@ export default { return r }, } satisfies ExportedHandler + +const redirect_lookup: Record = { + '/common_tools/': '/common-tools/', +} + +function redirect(pathname: string): string | null { + return redirect_lookup[pathname] ?? null +} diff --git a/docs/common_tools.md b/docs/common-tools.md similarity index 100% rename from docs/common_tools.md rename to docs/common-tools.md diff --git a/mkdocs.yml b/mkdocs.yml index 8c17e1aff4..0659d8c02e 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -20,7 +20,7 @@ nav: - models.md - dependencies.md - tools.md - - common_tools.md + - common-tools.md - results.md - message-history.md - testing-evals.md From b5fd7d2ae7f6e25d17a90e51f558a9430d41d4ab Mon Sep 17 00:00:00 2001 From: Samuel Colvin Date: Wed, 26 Mar 2025 10:57:38 +0000 Subject: [PATCH 2/3] debug redirects --- docs-site/src/index.ts | 7 ++++--- docs-site/wrangler.toml | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/docs-site/src/index.ts b/docs-site/src/index.ts index d0fa3bc2b2..2ba9f43e7c 100644 --- a/docs-site/src/index.ts +++ b/docs-site/src/index.ts @@ -3,6 +3,7 @@ export default { const r = await env.ASSETS.fetch(request) if (r.status == 404) { const url = new URL(request.url) + console.log({url, pathname: url.pathname}) const redirectPath = redirect(url.pathname) if (redirectPath) { url.pathname = redirectPath @@ -10,16 +11,16 @@ export default { } url.pathname = '/404.html' const r = await env.ASSETS.fetch(url) - return new Response(r.body, { status: 404 }) + return new Response(r.body, { status: 404, headers: {'content-type': 'text/html'} }) } return r }, } satisfies ExportedHandler const redirect_lookup: Record = { - '/common_tools/': '/common-tools/', + '/common_tools': '/common-tools/', } function redirect(pathname: string): string | null { - return redirect_lookup[pathname] ?? null + return redirect_lookup[pathname.replace(/\/+$/, '')] ?? null } diff --git a/docs-site/wrangler.toml b/docs-site/wrangler.toml index 068a90aba2..d99b9701d9 100644 --- a/docs-site/wrangler.toml +++ b/docs-site/wrangler.toml @@ -1,6 +1,6 @@ #:schema node_modules/wrangler/config-schema.json name = "pydantic-ai" -compatibility_date = "2025-01-29" +compatibility_date = "2025-01-24" routes = ["ai.pydantic.dev/*"] main = "src/index.ts" workers_dev = false From 888fead9cca26a94683484112a8242ce4d85ef29 Mon Sep 17 00:00:00 2001 From: Samuel Colvin Date: Wed, 26 Mar 2025 11:02:01 +0000 Subject: [PATCH 3/3] remove debug --- docs-site/src/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/docs-site/src/index.ts b/docs-site/src/index.ts index 2ba9f43e7c..2b535cf8a1 100644 --- a/docs-site/src/index.ts +++ b/docs-site/src/index.ts @@ -3,7 +3,6 @@ export default { const r = await env.ASSETS.fetch(request) if (r.status == 404) { const url = new URL(request.url) - console.log({url, pathname: url.pathname}) const redirectPath = redirect(url.pathname) if (redirectPath) { url.pathname = redirectPath