Skip to content

Commit 6d0c674

Browse files
Add middleware to inject topic metadata for Starlight search functionality
1 parent 4e50bfd commit 6d0c674

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

astro.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export default defineConfig({
3737
integrations: [
3838
starlight({
3939
customCss: ["./src/styles/custom.css"],
40+
routeMiddleware: ["./src/plugins/search-topic-middleware.ts"],
4041
plugins: [
4142
starlightLlmsTxt(),
4243
starlightHeadingBadges(),
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { defineRouteMiddleware } from "@astrojs/starlight/route-data";
2+
3+
const topics = [
4+
{ key: "/bff/", value: "Backend For Frontend Security Library" },
5+
{ key: "/accesstokenmanagement/", value: "Access Token Management" },
6+
{ key: "/general/", value: "General" },
7+
{ key: "/identitymodel/", value: "Identity Model" },
8+
{
9+
key: "/identitymodel-oidcclient/",
10+
value: "Identity Model - OpenID Connect Client",
11+
},
12+
{ key: "/identityserver/", value: "IdentityServer" },
13+
];
14+
15+
export const onRequest = defineRouteMiddleware((context) => {
16+
const { starlightRoute } = context.locals;
17+
const path = starlightRoute.entry.filePath;
18+
19+
const topic = topics.find((t) => path.includes(t.key))?.value ?? "Unknown";
20+
21+
starlightRoute.head.push({
22+
tag: "meta",
23+
attrs: { "data-pagefind-meta": `Topic: ${topic}` },
24+
});
25+
});

0 commit comments

Comments
 (0)