help: Make canonical URL for the root to be /help/.

We also make sure that /help/ is accessible when using the dev server.

We add vite as a dependency. v7 of vite is the latest version but using
that causes type problems for PluginOptions since astro uses vite v6.
Therefore we pin vite to v6 for now.

This commit also runs `pnpm dedupe` for `tinyglobby` pinning it to
0.2.15 instead of the previous 0.2.14 in the lockfile.
This commit is contained in:
Shubham Padia
2025-09-23 11:32:49 +00:00
committed by Tim Abbott
parent 72e3b94855
commit 9fa09f8f87
5 changed files with 65 additions and 8 deletions

View File

@@ -164,6 +164,7 @@
"svgo": "^4.0.0",
"typescript": "^5.0.2",
"typescript-eslint": "^8.13.0",
"vite": "^6.3.5",
"vnu-jar": "^24.10.17",
"webpack-dev-server": "^5.0.2",
"xvfb": "^0.4.0",

13
pnpm-lock.yaml generated
View File

@@ -513,6 +513,9 @@ importers:
typescript-eslint:
specifier: ^8.13.0
version: 8.42.0(eslint@9.34.0(jiti@2.5.1))(typescript@5.9.2)
vite:
specifier: ^6.3.5
version: 6.3.5(@types/node@22.18.1)(jiti@2.5.1)(terser@5.44.0)(yaml@2.8.1)
vnu-jar:
specifier: ^24.10.17
version: 24.10.17
@@ -8865,8 +8868,8 @@ packages:
tinyexec@1.0.1:
resolution: {integrity: sha512-5uC6DDlmeqiOwCPmK9jMSdOuZTh8bU39Ys6yidB+UTt5hfZUPGAypSgFRiEp+jbi9qH40BLDvy85jIU88wKSqw==}
tinyglobby@0.2.14:
resolution: {integrity: sha512-tX5e7OM1HnYr2+a2C/4V0htOcSQcoSTH9KgJnVvNm5zm/cyEWKJ7j7YutsH9CxMdtOkkLFy2AHrMci9IM8IPZQ==}
tinyglobby@0.2.15:
resolution: {integrity: sha512-j2Zq4NyQYG5XMST4cbs02Ak8iJUdxRM0XI5QyxXuZOzKOINmWurp3smXu3y5wDcJrptwpSjgXHzIQxR0omXljQ==}
engines: {node: '>=12.0.0'}
tinyqueue@2.0.3:
@@ -13008,7 +13011,7 @@ snapshots:
shiki: 3.12.2
smol-toml: 1.4.2
tinyexec: 0.3.2
tinyglobby: 0.2.14
tinyglobby: 0.2.15
tsconfck: 3.1.6(typescript@5.9.2)
ultrahtml: 1.6.0
unifont: 0.5.2
@@ -20388,7 +20391,7 @@ snapshots:
tinyexec@1.0.1: {}
tinyglobby@0.2.14:
tinyglobby@0.2.15:
dependencies:
fdir: 6.5.0(picomatch@4.0.3)
picomatch: 4.0.3
@@ -20964,7 +20967,7 @@ snapshots:
picomatch: 4.0.3
postcss: 8.5.6
rollup: 4.50.0
tinyglobby: 0.2.14
tinyglobby: 0.2.15
optionalDependencies:
'@types/node': 22.18.1
fsevents: 2.3.3

View File

@@ -27,8 +27,13 @@ location /static/ {
}
}
# Redirect to links without the trailing slash.
location ~ ^(/help(?:/[^/]+)*)/+$ {
# Canonical URL for the root is /help/.
location = /help {
return 301 /help/;
}
# Redirect to links without the trailing slash except for root /help/.
location ~ ^(/help(?:/[^/]+)+)/+$ {
return 301 $1$is_args$args;
}

View File

@@ -7,6 +7,53 @@ import {defineConfig, envField} from "astro/config";
import compressor from "astro-compressor";
import Icons from "unplugin-icons/vite";
/**
* @returns {import("vite").PluginOption}
*/
function createRedirectPlugin() {
// Astro and starlight middlewares run after astro's vite middleware,
// which gives error before our logic here could run, so the only option
// left with us was to use a vite plugin.
return {
name: "redirect-plugin",
enforce: "post",
/**
* configureServer only runs in development mode, we handle the redirects
* in production using nginx.
* @param {import("vite").ViteDevServer} server
*/
configureServer(server) {
return () => {
// The method exposed by the connect app at server.middlewares is `use`.
// But `use` appends our middleware at the end of the stack, before which
// the trailingSlashMiddleware of astro runs and gives an error before it
// can reach our middleware. `stack.unshift` ensures our middleware runs
// first.
server.middlewares.stack.unshift({
route: "",
/**
* @param {import("http").IncomingMessage} req
* @param {import("http").ServerResponse} _res
* @param {Function} next
*/
handle(req, _res, next) {
// Canonical URL for the root of the help center is /help/,
// but for all other help URLs, there should be no trailingSlash.
// We have set trailingSlash to never in astro. Setting it to ignore
// will make our /help/ work, but it causes sidebar and other
// components to generate links with a trailingSlash at the end. So
// we manually handle this case.
if (req.url === "/help/") {
req.url = "/help";
}
next();
},
});
};
},
};
}
// https://astro.build/config
export default defineConfig({
base: "help",
@@ -47,6 +94,7 @@ export default defineConfig({
}
},
}),
createRedirectPlugin(),
],
ssr: {
noExternal: ["zod"],

View File

@@ -49,4 +49,4 @@ API_FEATURE_LEVEL = 427
# historical commits sharing the same major version, in which case a
# minor version bump suffices.
PROVISION_VERSION = (351, 1) # bumped 2025-10-02 to add PyICU
PROVISION_VERSION = (351, 2) # bumped 2025-10-01 to add vite to starlight_help