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.

fix(docs): map site-root sidebar href to the 'index' page id in makeHrefToId (#10269)

Hu Hongweib39190bd3739
diff --git a/docs/src/lib/sidebar.mjs b/docs/src/lib/sidebar.mjs
index aa2410a4cd..7d858aa9bc 100644
--- a/docs/src/lib/sidebar.mjs
+++ b/docs/src/lib/sidebar.mjs
@@ -26,11 +26,16 @@ export const parentDirectory = (id) => id.slice(0, Math.max(id.lastIndexOf('/'),
/**
* Maps a sidebar link's href to the English docs page id, removing the deployment base path and any locale: a
- * translation mirrors its English file's name and directory, so English data drives every locale's sidebar.
+ * translation mirrors its English file's name and directory, so English data drives every locale's sidebar. The site
+ * root itself maps to 'index', the id `generateDocsId` gives the root `index.mdx` (only a trailing `/index` drops).
* @param {string} baseUrl
* @returns {(href: string) => string}
*/
-export const makeHrefToId = (baseUrl) => (href) => trimSlashes(splitSitePath(href, baseUrl)?.path ?? href);
+export const makeHrefToId = (baseUrl) => (href) => {
+ const path = splitSitePath(href, baseUrl)?.path;
+ if (path === undefined) return trimSlashes(href);
+ return path === '/' ? 'index' : trimSlashes(path);
+};
/**
* A docs file's directory as a URL path, e.g. `src/content/docs/Users Guide/03.Models/x.mdx` -> `users-guide/models`.
diff --git a/docs/src/lib/sidebar.test.mjs b/docs/src/lib/sidebar.test.mjs
index 64d7914462..b7840e3348 100644
--- a/docs/src/lib/sidebar.test.mjs
+++ b/docs/src/lib/sidebar.test.mjs
@@ -46,6 +46,19 @@ describe('generateDocsId', () => {
});
});
+describe('makeHrefToId', () => {
+ it("maps a homepage href to the 'index' page id, with or without a base path or a locale", () => {
+ assert.equal(hrefToId('/'), 'index');
+ assert.equal(makeHrefToId('/InvokeAI/')('/InvokeAI/'), 'index');
+ assert.equal(makeHrefToId('/InvokeAI/')('/InvokeAI/de/'), 'index');
+ });
+
+ it('strips the base path from deeper hrefs but leaves unrelated paths alone', () => {
+ assert.equal(makeHrefToId('/InvokeAI/')('/InvokeAI/video/wan/'), 'video/wan');
+ assert.equal(makeHrefToId('/InvokeAI/')('/other/page/'), 'other/page');
+ });
+});
+
describe('translateGroupLabels', () => {
it('translates group labels at every depth by their slug, keeping labels without a string and link labels', () => {
const german = {
@@ -204,6 +217,29 @@ describe('addCrossListings', () => {
addCrossListings(sidebar, [{ id: 'video/wan', directory: 'models/local' }], directories, baseHrefToId);
assert.deepEqual(labels(sidebar[0].entries), ['SDXL', 'Wan']);
});
+
+ it('cross-lists the homepage when a base path deploys its link at the base itself', () => {
+ const baseHrefToId = makeHrefToId('/InvokeAI/');
+ // The fixture ids come from the real ID generator and the frontmatter through the cross-listing selector, as in
+ // `route-data.ts`: the root `index.mdx` gets the id 'index', not ''.
+ const homeDoc = { id: generateDocsId({ entry: 'index.mdx', data: { alsoListedIn: ['docs'] } }), data: { alsoListedIn: ['docs'] } };
+ assert.equal(homeDoc.id, 'index');
+ const sidebar = [
+ group('Docs', 'docs', [{ ...link('docs/intro', 'Intro'), href: '/InvokeAI/docs/intro/' }]),
+ group('Home', '', [
+ { ...link('index', 'Home'), href: '/InvokeAI/' },
+ { ...link('video/wan', 'Wan'), href: '/InvokeAI/video/wan/' },
+ ]),
+ ];
+ const dirs = new Map([
+ ['docs/intro', 'docs'],
+ ['index', ''],
+ ['video/wan', ''],
+ ]);
+ addCrossListings(sidebar, selectCrossListings([homeDoc], true), dirs, baseHrefToId);
+ assert.deepEqual(labels(sidebar[0].entries), ['Home', 'Intro']);
+ assert.ok(CROSS_LISTED_ATTR in sidebar[0].entries[0].attrs);
+ });
});
describe('locale routes', () => {
@@ -213,7 +249,7 @@ describe('locale routes', () => {
it("maps a translated or fallback page's href to the English page id", () => {
assert.equal(localeHrefToId('/InvokeAI/de/users-guide/gallery/boards/'), 'users-guide/gallery/boards');
- assert.equal(localeHrefToId('/InvokeAI/hi/'), '');
+ assert.equal(localeHrefToId('/InvokeAI/hi/'), 'index');
// Only a known locale is a locale segment.
assert.equal(localeHrefToId('/InvokeAI/development/x/'), 'development/x');
assert.equal(localeHrefToId('/InvokeAI/it/x/'), 'it/x');