From 5a13a7d5da625a6d44a06e8a1cc7f95fc569ad7e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 27 Mar 2026 02:36:57 +0000 Subject: [PATCH 1/2] feat(website): add charset header, integrity attributes, and disable directory indexing - Create Astro middleware to set Content-Type charset=utf-8 for all HTML responses - Add integrity attribute (SHA-384) to 1ds-init.js script in base-layout and Starlight config - Add crossorigin="anonymous" to external wcp-consent.js script - Disable directory indexing for /docs/handbook/configuration/configuration/ via meta robots tag and middleware X-Robots-Tag header Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/7dfd7541-76dc-4f3c-9397-bdedcfaca7a0 Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com> --- website/astro.config.mjs | 2 ++ .../handbook/configuration/configuration.mdx | 5 +++++ website/src/layouts/base-layout.astro | 11 +++++++--- website/src/middleware.ts | 21 +++++++++++++++++++ 4 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 website/src/middleware.ts diff --git a/website/astro.config.mjs b/website/astro.config.mjs index b495713134e..84390e5b504 100644 --- a/website/astro.config.mjs +++ b/website/astro.config.mjs @@ -98,6 +98,7 @@ export default defineConfig({ tag: "script", attrs: { src: "https://consentdeliveryfd.azurefd.net/mscc/lib/v2/wcp-consent.js", + crossorigin: "anonymous", }, }, { @@ -106,6 +107,7 @@ export default defineConfig({ type: "module", async: true, src: "1ds-init.js", + integrity: "sha384-idYZGvEvTNaaqBGjIeT/diHjEM13+k+Utpb4k+TjTW/ui8yYALU1FXvgk+lG/EZG", }, }, ], diff --git a/website/src/content/docs/docs/handbook/configuration/configuration.mdx b/website/src/content/docs/docs/handbook/configuration/configuration.mdx index 2c53ec7ec14..68a491bc92d 100644 --- a/website/src/content/docs/docs/handbook/configuration/configuration.mdx +++ b/website/src/content/docs/docs/handbook/configuration/configuration.mdx @@ -1,5 +1,10 @@ --- title: Configuration +head: + - tag: meta + attrs: + name: robots + content: noindex --- import { FileTree } from "@astrojs/starlight/components"; diff --git a/website/src/layouts/base-layout.astro b/website/src/layouts/base-layout.astro index 4d2361eab40..8aef70ced5d 100644 --- a/website/src/layouts/base-layout.astro +++ b/website/src/layouts/base-layout.astro @@ -18,9 +18,14 @@ const { footer = true } = Astro.props; typespec.io - - + +
diff --git a/website/src/middleware.ts b/website/src/middleware.ts new file mode 100644 index 00000000000..b20ef79fe3f --- /dev/null +++ b/website/src/middleware.ts @@ -0,0 +1,21 @@ +import { defineMiddleware } from "astro:middleware"; + +export const onRequest = defineMiddleware(async (context, next) => { + const response = await next(); + const contentType = response.headers.get("content-type"); + + // Set charset=utf-8 for all HTML responses + if (contentType?.includes("text/html")) { + response.headers.set("content-type", "text/html; charset=utf-8"); + } + + // Disable directory indexing for the configuration page + if ( + context.url.pathname === "/docs/handbook/configuration/configuration/" || + context.url.pathname === "/docs/handbook/configuration/configuration" + ) { + response.headers.set("X-Robots-Tag", "noindex"); + } + + return response; +}); From 88fdab9136269f774921851c40ba7a4325262bcd Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 27 Mar 2026 02:39:37 +0000 Subject: [PATCH 2/2] refactor: simplify pathname check in middleware Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/7dfd7541-76dc-4f3c-9397-bdedcfaca7a0 Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com> --- website/src/middleware.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/website/src/middleware.ts b/website/src/middleware.ts index b20ef79fe3f..4748975cb5a 100644 --- a/website/src/middleware.ts +++ b/website/src/middleware.ts @@ -10,10 +10,8 @@ export const onRequest = defineMiddleware(async (context, next) => { } // Disable directory indexing for the configuration page - if ( - context.url.pathname === "/docs/handbook/configuration/configuration/" || - context.url.pathname === "/docs/handbook/configuration/configuration" - ) { + const normalizedPath = context.url.pathname.replace(/\/$/, ""); + if (normalizedPath === "/docs/handbook/configuration/configuration") { response.headers.set("X-Robots-Tag", "noindex"); }