From e3aca9e4f6287fddea71ca61587d9a2f370ad21d Mon Sep 17 00:00:00 2001 From: Zeno Kapitein Date: Sat, 18 Apr 2026 00:43:07 +0200 Subject: [PATCH] Fix embeddable search links (#4196) --- .changeset/salty-chefs-shout.md | 5 ++ .../Embeddable/EmbeddableDocsPage.tsx | 4 +- .../SiteSections/encodeClientSiteSections.ts | 59 +++++++++++++++---- packages/gitbook/src/lib/embeddable-linker.ts | 21 +++++-- packages/gitbook/src/lib/embeddable.test.ts | 54 +++++++++++++++++ 5 files changed, 126 insertions(+), 17 deletions(-) create mode 100644 .changeset/salty-chefs-shout.md diff --git a/.changeset/salty-chefs-shout.md b/.changeset/salty-chefs-shout.md new file mode 100644 index 000000000..c86822360 --- /dev/null +++ b/.changeset/salty-chefs-shout.md @@ -0,0 +1,5 @@ +--- +"gitbook": patch +--- + +Fix embeddable search links diff --git a/packages/gitbook/src/components/Embeddable/EmbeddableDocsPage.tsx b/packages/gitbook/src/components/Embeddable/EmbeddableDocsPage.tsx index bcaea9c98..2eb0acceb 100644 --- a/packages/gitbook/src/components/Embeddable/EmbeddableDocsPage.tsx +++ b/packages/gitbook/src/components/Embeddable/EmbeddableDocsPage.tsx @@ -82,7 +82,9 @@ export async function EmbeddableDocsPage( {context.sections ? ( {variants.translations.length > 1 ? ( { ) ).toBe('/api/python/~gitbook/embed/page/getting-started'); }); + + it('toEmbeddableLinkForPublishedContent should not duplicate the embed path for embeddable linkers', () => { + const root = createLinker({ + host: 'docs.company.com', + spaceBasePath: '/docs', + siteBasePath: '/', + }); + + const embeddableLinker = getEmbeddableLinker(root); + + expect( + toEmbeddableLinkForPublishedContent( + embeddableLinker, + 'https://docs.company.com/docs', + 'nested/page-path' + ) + ).toBe('/docs/~gitbook/embed/page/nested/page-path'); + }); + + it('toEmbeddableLinkForPublishedContent should place section paths before the embed path', () => { + const root = createLinker({ + host: 'docs.company.com', + spaceBasePath: '/docs', + siteBasePath: '/', + }); + + const embeddableLinker = getEmbeddableLinker(root); + + expect( + toEmbeddableLinkForPublishedContent( + embeddableLinker, + 'https://docs.company.com/docs/guides', + '' + ) + ).toBe('/docs/guides/~gitbook/embed/page'); + }); + + it('toEmbeddableLinkForPublishedContent should keep page slugs after the embed path in other sections', () => { + const root = createLinker({ + host: 'docs.company.com', + spaceBasePath: '/docs', + siteBasePath: '/', + }); + + const embeddableLinker = getEmbeddableLinker(root); + + expect( + toEmbeddableLinkForPublishedContent( + embeddableLinker, + 'https://docs.company.com/docs/guides', + 'getting-started' + ) + ).toBe('/docs/guides/~gitbook/embed/page/getting-started'); + }); }); describe('resolveEmbeddableTheme', () => {