Skip to content

Commit

Permalink
add noindex to metatdata when applicable
Browse files Browse the repository at this point in the history
  • Loading branch information
Beth Shook committed Jun 24, 2024
1 parent 1580b99 commit e9460bf
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
23 changes: 23 additions & 0 deletions src/app/content/hooks/receiveContent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'},
]),
})));
});
});
});
2 changes: 1 addition & 1 deletion src/app/content/hooks/receiveContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const hookBody: ActionHookBody<typeof receivePage | typeof locationChange> = (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' });
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/content/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,6 @@ function reduceReceiveBook(state: State, action: ActionType<typeof actions.recei

function reduceReceivePage(state: State, action: ActionType<typeof actions.receivePage>) {
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};
}
2 changes: 2 additions & 0 deletions src/app/content/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export interface Page {
id: string;
title: string;
slug: string;
noindex?: boolean;
}

export interface ArchiveTreeNode {
Expand Down Expand Up @@ -165,6 +166,7 @@ export interface ArchivePage {
title: string;
revised: string;
slug: string;
noindex?: boolean;
}

export type ArchiveContent = ArchivePage | ArchiveBook;

0 comments on commit e9460bf

Please sign in to comment.