Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions website/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export default defineConfig({
tag: "script",
attrs: {
src: "https://consentdeliveryfd.azurefd.net/mscc/lib/v2/wcp-consent.js",
crossorigin: "anonymous",
},
},
{
Expand All @@ -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",
},
},
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
---
title: Configuration
head:
- tag: meta
attrs:
name: robots
content: noindex
---

import { FileTree } from "@astrojs/starlight/components";
Expand Down
11 changes: 8 additions & 3 deletions website/src/layouts/base-layout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@ const { footer = true } = Astro.props;
<link rel="og:image" type="image/svg+xml" href={baseUrl("/img/social.svg")} />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>typespec.io</title>
<script src="https://consentdeliveryfd.azurefd.net/mscc/lib/v2/wcp-consent.js" is:inline
></script>
<script src={import.meta.env.BASE_URL + "1ds-init.js"} is:inline></script>
<script
src="https://consentdeliveryfd.azurefd.net/mscc/lib/v2/wcp-consent.js"
crossorigin="anonymous"
is:inline></script>
<script
src={import.meta.env.BASE_URL + "1ds-init.js"}
integrity="sha384-idYZGvEvTNaaqBGjIeT/diHjEM13+k+Utpb4k+TjTW/ui8yYALU1FXvgk+lG/EZG"
is:inline></script>
</head>
<body class="body">
<header class="header">
Expand Down
33 changes: 33 additions & 0 deletions website/src/middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { defineMiddleware } from "astro:middleware";

/**
* Returns true when the MIME type is text-based and should carry charset=utf-8.
* Covers text/* (html, plain, css, …), XML flavours (image/svg+xml,
* application/xml, …), JSON, and JavaScript / shell-script types.
*/
function isTextBasedContentType(contentType: string): boolean {
if (contentType.startsWith("text/")) return true;
if (contentType.includes("/xml") || contentType.includes("+xml")) return true;
if (contentType.includes("/json") || contentType.includes("+json")) return true;
if (contentType.includes("/javascript")) return true;
if (contentType.includes("/x-sh")) return true;
return false;
}

export const onRequest = defineMiddleware(async (context, next) => {
const response = await next();
const contentType = response.headers.get("content-type");

// Add charset=utf-8 for text-based content types that don't already specify one
if (contentType && !contentType.includes("charset") && isTextBasedContentType(contentType)) {
response.headers.set("content-type", `${contentType}; charset=utf-8`);
}

// Disable directory indexing for the configuration page
const normalizedPath = context.url.pathname.replace(/\/$/, "");
if (normalizedPath === "/docs/handbook/configuration/configuration") {
response.headers.set("X-Robots-Tag", "noindex");
}

return response;
});
Loading