mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-17 16:15:22 +00:00
64a9e27ca7
* 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
40 lines
1.0 KiB
TypeScript
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;
|
|
}
|