Skip to content
Discussion options

You must be logged in to vote

Here's a working version of the route middleware idea from above. It drops every sidebar link that has no file of its own in the current language. The default language keeps everything, since all of its pages exist.

src/routeData.ts:

import { defineRouteMiddleware, type StarlightRouteData } from '@astrojs/starlight/route-data';
import { getCollection } from 'astro:content';

type Entry = StarlightRouteData['sidebar'][number];
type Link = Extract<Entry, { type: 'link' }>;

// ids of pages that actually have a file, like "zh-cn/guide/a" or "en/guide/a"
let pageIds: Set<string> | undefined;

export const onRequest = defineRouteMiddleware(async ({ locals }) => {
  const route = locals.starlig…

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@yangxuan74
Comment options

@delucis
Comment options

Comment options

You must be logged in to vote
1 reply
@yangxuan74
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by yangxuan74
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants