diff --git a/.changeset/hide-anchor-links-landing.md b/.changeset/hide-anchor-links-landing.md new file mode 100644 index 000000000..4628ca658 --- /dev/null +++ b/.changeset/hide-anchor-links-landing.md @@ -0,0 +1,5 @@ +--- +"gitbook": patch +--- + +Hide heading and expandable anchor links on pages whose layout disables anchors (landing pages). diff --git a/bun.lock b/bun.lock index d524c74fb..49f34f685 100644 --- a/bun.lock +++ b/bun.lock @@ -355,7 +355,7 @@ }, "catalog": { "@base-ui/react": "^1.7.0", - "@gitbook/api": "0.201.0", + "@gitbook/api": "0.202.0", "@scalar/api-client-react": "^1.3.46", "@tsconfig/node20": "^20.1.6", "@tsconfig/strictest": "^2.0.6", @@ -727,7 +727,7 @@ "@fortawesome/fontawesome-svg-core": ["@fortawesome/fontawesome-svg-core@7.2.0", "", { "dependencies": { "@fortawesome/fontawesome-common-types": "7.2.0" } }, "sha512-6639htZMjEkwskf3J+e6/iar+4cTNM9qhoWuRfj9F3eJD6r7iCzV1SWnQr2Mdv0QT0suuqU8BoJCZUyCtP9R4Q=="], - "@gitbook/api": ["@gitbook/api@0.201.0", "", { "dependencies": { "event-iterator": "^2.0.0", "eventsource-parser": "^3.0.0" } }, "sha512-bI+FyExZrz9V8yaMBOo4k2QHb0nJvrHYKXE+Svb3Dr1/kYA1bdyL5swCDCH9MxaRQjjJlN3VilvPmblKOYLuVA=="], + "@gitbook/api": ["@gitbook/api@0.202.0", "", { "dependencies": { "event-iterator": "^2.0.0", "eventsource-parser": "^3.0.0" } }, "sha512-qhrjEQbNNmCljR0AgP79+BsVh9yelh9TIBg9X3TyYx5a3lJwDiT3sw1ND9DFQSxGHp8hH5w+20KJHn/IDpTbaw=="], "@gitbook/browser-types": ["@gitbook/browser-types@workspace:packages/browser-types"], diff --git a/package.json b/package.json index 43e720205..f0413b1e7 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@tsconfig/strictest": "^2.0.6", "@tsconfig/node20": "^20.1.6", "@base-ui/react": "^1.7.0", - "@gitbook/api": "0.201.0", + "@gitbook/api": "0.202.0", "@scalar/api-client-react": "^1.3.46", "@types/react": "^19.0.0", "@types/react-dom": "^19.0.0", diff --git a/packages/gitbook/e2e/internal.spec.ts b/packages/gitbook/e2e/internal.spec.ts index 22806f570..a3d6055c2 100644 --- a/packages/gitbook/e2e/internal.spec.ts +++ b/packages/gitbook/e2e/internal.spec.ts @@ -1747,7 +1747,6 @@ const testCases: TestsCase[] = [ { name: 'Without previewed ads', url: 'text-page?ads_preview=1', - run: waitForCookiesDialog, }, ], }, diff --git a/packages/gitbook/src/components/DocumentView/Expandable/Expandable.tsx b/packages/gitbook/src/components/DocumentView/Expandable/Expandable.tsx index 2c8e4d05c..2c3832930 100644 --- a/packages/gitbook/src/components/DocumentView/Expandable/Expandable.tsx +++ b/packages/gitbook/src/components/DocumentView/Expandable/Expandable.tsx @@ -3,6 +3,7 @@ import { Icon } from '@gitbook/icons'; import type { BlockProps } from '../Block'; import { Blocks } from '../Blocks'; +import { shouldShowHashLinks } from '../HashLinkButton'; import { Inlines } from '../Inlines'; import { Details } from './Details'; import { ToggleChevron } from '@/components/primitives'; @@ -31,6 +32,8 @@ export async function Expandable(props: BlockProps) { ? await getSpaceLanguage(context.contentContext) : defaultLanguage; + const showHashLink = shouldShowHashLinks(context); + return (
) { className={tcls( 'cursor-pointer', 'px-4', - 'pr-10', + // Reserve room for the anchor icon pinned to the right edge + showHashLink && 'pr-10', 'py-4', 'relative', 'list-none', @@ -71,32 +75,34 @@ export async function Expandable(props: BlockProps) { context={context} ancestorInlines={[]} /> - - - + > + + + ) : null} ) { ? await getSpaceLanguage(context.contentContext) : defaultLanguage; + const showHashLink = shouldShowHashLinks(context); + return ( ) { 'font-heading', 'pdf-heading', 'block', - 'pr-6', + // Reserve room for the absolutely positioned anchor icon on coarse pointers + showHashLink && 'pr-6', 'pointer-fine:flex', 'pointer-fine:items-baseline', 'pointer-fine:pr-0', @@ -63,20 +66,22 @@ export async function Heading(props: BlockProps) { - + {showHashLink ? ( + + ) : null} ); } diff --git a/packages/gitbook/src/lib/pages.test.ts b/packages/gitbook/src/lib/pages.test.ts index f74da9131..6b3306cea 100644 --- a/packages/gitbook/src/lib/pages.test.ts +++ b/packages/gitbook/src/lib/pages.test.ts @@ -89,6 +89,7 @@ describe('resolveFirstDocument', () => { metadata: true, tags: true, actions: true, + anchors: true, }, }, ], @@ -143,6 +144,7 @@ describe('resolveFirstDocument', () => { metadata: true, tags: true, actions: true, + anchors: true, }, }, ]; @@ -190,6 +192,7 @@ describe('resolvePagePath', () => { metadata: true, tags: true, actions: true, + anchors: true, }, }, ]; @@ -267,6 +270,7 @@ describe('resolvePagePath', () => { metadata: true, tags: true, actions: true, + anchors: true, }, }, ], @@ -386,6 +390,7 @@ function createDocumentPage(id: string, path: string, hidden = false): RevisionP metadata: true, tags: true, actions: true, + anchors: true, }, }; }