Files
gitbook/src/lib/seo.ts
T
Samy Pessé 64a9e27ca7 Resolve revision and change request URL correctly (#98)
* Add tests for getURLLookupAlternatives

* Match correctly revisions and changes URLs

* Use revision and changerequets ID passed from lookup

* Prevent indexing these urls

* Start

* Start rendering toolbar

* Update api client

* Format

* Format

* Mock resolve of snippet

* Add test for revision
2024-01-15 09:42:38 +01:00

40 lines
1.0 KiB
TypeScript

import { Collection, ContentVisibility, Space } from '@gitbook/api';
import { headers } from 'next/headers';
/**
* Return true if a space should be indexed by search engines.
*/
export function shouldIndexSpace({
space,
collection,
}: {
space: Space;
collection: Collection | null;
}) {
const headerSet = headers();
if (
process.env.GITBOOK_BLOCK_SEARCH_INDEXATION &&
!headerSet.has('x-gitbook-search-indexation')
) {
return false;
}
// Prevent indexation of preview of revisions / change-requests
if (
headerSet.get('x-gitbook-content-revision') ||
headerSet.get('x-gitbook-content-changerequest')
) {
return false;
}
if (space.visibility === ContentVisibility.InCollection) {
return collection ? shouldIndexVisibility(collection.visibility) : false;
}
return shouldIndexVisibility(space.visibility);
}
function shouldIndexVisibility(visibility: ContentVisibility) {
return visibility === ContentVisibility.Public;
}