Skip to content

Autgenerate Sidebar from Custom Pages #2959

Closed Answered by HiDeoo
stevegreco asked this question in Q&A
Discussion options

You must be logged in to vote

The example uses a literal list of strings but it's mostly for the example purposes only. If it was fetched from the network, it would be the same and the network call could be done in getPages().

Regarding the approach when using getCollection(), you could still do the same and do the call in getPages() but instead of using getSidebarLinks() in your config, you can use it in a route data middleware to append your links:

// src/routeData.ts
import { defineRouteMiddleware } from '@astrojs/starlight/route-data';
import { getSidebarLinks } from "./libs/content.ts";

export const onRequest = defineRouteMiddleware(async (context) => {
  // Get the sidebar for this page.
  const { sidebar } = c…

Replies: 1 comment 2 replies

Comment options

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

@HiDeoo
Comment options

Answer selected by HiDeoo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants