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', () => {