Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

feat(docs): list pages in a second sidebar group with alsoListedIn

Lincoln Steinc2a8c6171e1a
diff --git a/docs/src/content.config.ts b/docs/src/content.config.ts
index 194c309e26..dc15607ef9 100644
--- a/docs/src/content.config.ts
+++ b/docs/src/content.config.ts
@@ -1,4 +1,5 @@
import { defineCollection } from 'astro:content';
+import { z } from 'astro/zod';
import { docsLoader, i18nLoader } from '@astrojs/starlight/loaders';
import { docsSchema, i18nSchema } from '@astrojs/starlight/schema';
@@ -7,7 +8,16 @@ import { changelogsLoader } from 'starlight-changelogs/loader';
import { generateDocsId } from './lib/sort-prefix.mjs';
export const collections = {
- docs: defineCollection({ loader: docsLoader({ generateId: generateDocsId }), schema: docsSchema() }),
+ docs: defineCollection({
+ loader: docsLoader({ generateId: generateDocsId }),
+ schema: docsSchema({
+ extend: z.object({
+ // Docs directories, as URL paths (e.g. `users-guide/models/local-models`), whose sidebar groups also list
+ // this page. See `src/route-data.ts`.
+ alsoListedIn: z.array(z.string()).optional(),
+ }),
+ }),
+ }),
i18n: defineCollection({ loader: i18nLoader(), schema: i18nSchema() }),
changelogs: defineCollection({
loader: changelogsLoader([
diff --git a/docs/src/content/docs/Users Guide/05.Video Generation/ltx-2.mdx b/docs/src/content/docs/Users Guide/05.Video Generation/ltx-2.mdx
index b56192f52a..aef7307593 100644
--- a/docs/src/content/docs/Users Guide/05.Video Generation/ltx-2.mdx
+++ b/docs/src/content/docs/Users Guide/05.Video Generation/ltx-2.mdx
@@ -1,6 +1,8 @@
---
title: LTX-2
lastUpdated: 2026-09-29
+alsoListedIn:
+ - users-guide/models/local-models
sidebar:
order: 3
---
diff --git a/docs/src/content/docs/Users Guide/05.Video Generation/minimax-h3.mdx b/docs/src/content/docs/Users Guide/05.Video Generation/minimax-h3.mdx
index 63b591e21b..0b05b218d5 100644
--- a/docs/src/content/docs/Users Guide/05.Video Generation/minimax-h3.mdx
+++ b/docs/src/content/docs/Users Guide/05.Video Generation/minimax-h3.mdx
@@ -1,6 +1,8 @@
---
title: MiniMax H3
lastUpdated: 2026-09-29
+alsoListedIn:
+ - users-guide/models/local-models
sidebar:
order: 2
---
diff --git a/docs/src/content/docs/Users Guide/05.Video Generation/wan-2.2.mdx b/docs/src/content/docs/Users Guide/05.Video Generation/wan-2.2.mdx
index ef7a9c006a..dac89e5ed4 100644
--- a/docs/src/content/docs/Users Guide/05.Video Generation/wan-2.2.mdx
+++ b/docs/src/content/docs/Users Guide/05.Video Generation/wan-2.2.mdx
@@ -1,6 +1,8 @@
---
title: Wan 2.2
lastUpdated: 2026-09-29
+alsoListedIn:
+ - users-guide/models/local-models
sidebar:
order: 1
---
diff --git a/docs/src/route-data.ts b/docs/src/route-data.ts
index 3a7f15fc07..0efa13ef67 100644
--- a/docs/src/route-data.ts
+++ b/docs/src/route-data.ts
@@ -1,7 +1,7 @@
import { getCollection } from 'astro:content';
import { defineRouteMiddleware, type StarlightRouteData } from '@astrojs/starlight/route-data';
-import { getSortPrefix, stripSortPrefix } from './lib/sort-prefix.mjs';
+import { generateDocsId, getSortPrefix, stripSortPrefix } from './lib/sort-prefix.mjs';
type SidebarEntry = StarlightRouteData['sidebar'][number];
type SidebarLink = Extract<SidebarEntry, { type: 'link' }>;
@@ -9,11 +9,38 @@ type PrevNextConfig = StarlightRouteData['entry']['data']['prev'];
const trimSlashes = (path: string) => path.replace(/^\/+|\/+$/g, '');
const basePath = trimSlashes(import.meta.env.BASE_URL);
+const parentDirectory = (id: string) => id.slice(0, Math.max(id.lastIndexOf('/'), 0));
-/** Maps each docs page id to its file name, which keeps the sorting prefix the id drops. */
-const getFileNamesById = async () => {
+type CrossListing = { id: string; directory: string };
+
+/** Marks the copy of a link that a page's `alsoListedIn` frontmatter adds; pagination skips these. */
+const CROSS_LISTED_ATTR = 'data-cross-listed';
+
+/** A docs file's directory as a URL path, e.g. `Users Guide/03.Models/x.mdx` -> `users-guide/models`. */
+const fileDirectory = (filePath: string | undefined) => {
+ const relative = filePath?.split('content/docs/').pop() ?? '';
+ const directory = relative.slice(0, Math.max(relative.lastIndexOf('/'), 0));
+ // A placeholder file name, because generateDocsId drops a trailing extension-like segment.
+ return directory ? parentDirectory(generateDocsId({ entry: `${directory}/page.md`, data: {} })) : '';
+};
+
+const getDocsIndex = async () => {
const docs = await getCollection('docs');
- return new Map(docs.map((doc) => [doc.id, doc.filePath?.split('/').pop() ?? '']));
+ return {
+ /** Maps each docs page id to its file name, which keeps the sorting prefix the id drops. */
+ fileNames: new Map(docs.map((doc) => [doc.id, doc.filePath?.split('/').pop() ?? ''])),
+ /** Maps each docs page id to its file's directory, which a custom slug or an index page's id does not show. */
+ directories: new Map(docs.map((doc) => [doc.id, fileDirectory(doc.filePath)])),
+ // Starlight leaves draft (in production) and hidden pages out of the sidebar, so there is nothing to copy.
+ crossListings: docs
+ .filter((doc) => !doc.data.sidebar.hidden && !(doc.data.draft && import.meta.env.PROD))
+ .flatMap((doc): CrossListing[] =>
+ (doc.data.alsoListedIn ?? []).map((directory) => ({
+ id: doc.id,
+ directory: trimSlashes(directory),
+ }))
+ ),
+ };
};
const hrefToId = (href: string) => {
@@ -56,6 +83,63 @@ const sortAndRelabel = (entries: SidebarEntry[], fileNames: Map<string, string>)
const flattenLinks = (entries: SidebarEntry[]): SidebarLink[] =>
entries.flatMap((entry) => (entry.type === 'group' ? flattenLinks(entry.entries) : [entry]));
+/**
+ * The group autogenerated from a docs directory: the one whose own links are pages in that directory. A directory
+ * holding only subdirectories cannot be found this way.
+ */
+const findDirectoryGroup = (
+ entries: SidebarEntry[],
+ directory: string,
+ directories: Map<string, string>
+): SidebarEntry[] | undefined => {
+ if (entries.some((entry) => entry.type === 'link' && directories.get(hrefToId(entry.href)) === directory)) {
+ return entries;
+ }
+ for (const entry of entries) {
+ const found = entry.type === 'group' ? findDirectoryGroup(entry.entries, directory, directories) : undefined;
+ if (found) return found;
+ }
+ return undefined;
+};
+
+/**
+ * Autogenerated sidebars list each page once, under its own directory. Add a copy of each cross-listed page's link
+ * to the group of every directory its `alsoListedIn` frontmatter names, placed alphabetically by label among that
+ * group's links (so target directories should order their pages alphabetically). A misconfigured listing fails the
+ * build.
+ */
+const addCrossListings = (
+ sidebar: SidebarEntry[],
+ crossListings: CrossListing[],
+ directories: Map<string, string>
+): boolean => {
+ if (crossListings.length === 0) return false;
+ const linksById = new Map(flattenLinks(sidebar).map((link) => [hrefToId(link.href), link]));
+ for (const { id, directory } of crossListings) {
+ const link = linksById.get(id);
+ if (!link) throw new Error(`Cross-listed page "${id}" has no sidebar link.`);
+ if (directories.get(id) === directory) throw new Error(`Page "${id}" is cross-listed in its own directory.`);
+ const group = findDirectoryGroup(sidebar, directory, directories);
+ if (!group) {
+ throw new Error(`Page "${id}" is cross-listed in "${directory}", which has no sidebar group with pages.`);
+ }
+ // Before the first link that sorts after it, else before the group's first subgroup, else last.
+ const laterLink = group.findIndex(
+ (entry) => entry.type === 'link' && entry.label.localeCompare(link.label, 'en', { sensitivity: 'base' }) > 0
+ );
+ const firstGroup = group.findIndex((entry) => entry.type === 'group');
+ const index = laterLink !== -1 ? laterLink : firstGroup !== -1 ? firstGroup : group.length;
+ // The page's own link carries the current-page state, so the copy never does.
+ const copy: SidebarLink = {
+ ...link,
+ isCurrent: false,
+ attrs: { ...link.attrs, [CROSS_LISTED_ATTR]: '' },
+ };
+ group.splice(index, 0, copy);
+ }
+ return true;
+};
+
/** Mirrors Starlight's handling of the frontmatter `prev`/`next` options for a regenerated neighbour link. */
const applyPrevNextConfig = (link: SidebarLink | undefined, config: PrevNextConfig): SidebarLink | undefined => {
if (config === false) return undefined;
@@ -71,10 +155,13 @@ const applyPrevNextConfig = (link: SidebarLink | undefined, config: PrevNextConf
export const onRequest = defineRouteMiddleware(async (context) => {
const route = context.locals.starlightRoute;
// Starlight hands each render its own copy of the sidebar.
- if (!sortAndRelabel(route.sidebar, await getFileNamesById())) return;
+ const { fileNames, directories, crossListings } = await getDocsIndex();
+ const reordered = sortAndRelabel(route.sidebar, fileNames);
+ const crossListed = addCrossListings(route.sidebar, crossListings, directories);
+ if (!reordered && !crossListed) return;
// Starlight derived prev/next links before the reorder. This site keeps the default `pagination: true`.
- const links = flattenLinks(route.sidebar);
+ const links = flattenLinks(route.sidebar).filter((link) => !(CROSS_LISTED_ATTR in link.attrs));
const current = links.findIndex((link) => link.isCurrent);
if (current === -1) return;
const { data } = route.entry;