diff --git a/src/app/content/hooks/receiveContent.spec.ts b/src/app/content/hooks/receiveContent.spec.ts index e7127e79cc..802721f4b0 100644 --- a/src/app/content/hooks/receiveContent.spec.ts +++ b/src/app/content/hooks/receiveContent.spec.ts @@ -219,5 +219,28 @@ describe('setHead hook', () => { ]), }))); }); + + it('dispatches sethead with robots:noindex tag if page has noindex set', async() => { + store.dispatch(receiveBook(combinedBook)); + store.dispatch(receivePage({ + ...page, + references: [], + noindex: true, + })); + const bookId = book.id; + CANONICAL_MAP[bookId] = [ [bookId, {}] ]; + + await hook(receivePage({ + ...page, + references: [], + noindex: true, + })); + + expect(dispatch).toHaveBeenCalledWith(setHead(expect.objectContaining({ + meta: expect.arrayContaining([ + {name: 'robots', content: 'noindex'}, + ]), + }))); + }); }); }); diff --git a/src/app/content/hooks/receiveContent.ts b/src/app/content/hooks/receiveContent.ts index d3a4d39d1d..00b9e04ce8 100644 --- a/src/app/content/hooks/receiveContent.ts +++ b/src/app/content/hooks/receiveContent.ts @@ -77,7 +77,7 @@ const hookBody: ActionHookBody = (se meta.push({ property: 'og:image', content: book.promote_image.meta.download_url }); } - if (book.loadOptions.archiveVersion || book.loadOptions.contentVersion) { + if (book.loadOptions.archiveVersion || book.loadOptions.contentVersion || page.noindex) { meta.push({ name: 'robots', content: 'noindex' }); } diff --git a/src/app/content/reducer.ts b/src/app/content/reducer.ts index d609a74580..42bae76feb 100644 --- a/src/app/content/reducer.ts +++ b/src/app/content/reducer.ts @@ -148,6 +148,6 @@ function reduceReceiveBook(state: State, action: ActionType) { const loading = omit('page', state.loading); - const page = pick(['abstract', 'id', 'title', 'version'], action.payload); + const page = pick(['abstract', 'id', 'title', 'version', 'noindex'], action.payload); return {...state, loading, page, references: action.payload.references}; } diff --git a/src/app/content/types.ts b/src/app/content/types.ts index d935691c79..bf65c2a001 100644 --- a/src/app/content/types.ts +++ b/src/app/content/types.ts @@ -107,6 +107,7 @@ export interface Page { id: string; title: string; slug: string; + noindex?: boolean; } export interface ArchiveTreeNode { @@ -165,6 +166,7 @@ export interface ArchivePage { title: string; revised: string; slug: string; + noindex?: boolean; } export type ArchiveContent = ArchivePage | ArchiveBook;