Skip to content

Commit 0aae142

Browse files
authored
Merge pull request #810 from DuendeSoftware/search-topic-tag
Add middleware to inject topic metadata for Starlight search
2 parents 4e50bfd + 07368a2 commit 0aae142

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: "BFF Security Framework" },
5+
{ key: "/accesstokenmanagement/", value: "Access Token Management" },
6+
{ key: "/general/", value: "General" },
7+
{ key: "/identitymodel/", value: "IdentityModel" },
8+
{
9+
key: "/identitymodel-oidcclient/",
10+
value: "IdentityModel.OidcClient",
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)