Skip to content

Commit 1992430

Browse files
authored
Merge pull request #4838 from atmire/w2p-136225_fix-upstream-private-items-issue-11569-8_x
Add noindex robots meta tag for non-discoverable items (8_x)
2 parents 0f2bd0e + 1cebae9 commit 1992430

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed

src/app/core/metadata/head-tag.service.spec.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
MockBitstream1,
2525
MockBitstream2,
2626
MockBitstream3,
27+
NonDiscoverableItemMock,
2728
} from '../../shared/mocks/item.mock';
2829
import { getMockTranslateService } from '../../shared/mocks/translate.service.mock';
2930
import {
@@ -128,6 +129,37 @@ describe('HeadTagService', () => {
128129
);
129130
});
130131

132+
describe(`robots tag`, () => {
133+
it(`should be set to noindex for non-discoverable items`, fakeAsync(() => {
134+
(headTagService as any).processRouteChange({
135+
data: {
136+
value: {
137+
dso: createSuccessfulRemoteDataObject(NonDiscoverableItemMock),
138+
},
139+
},
140+
});
141+
tick();
142+
expect(meta.addTag).toHaveBeenCalledWith({
143+
name: 'robots',
144+
content: 'noindex',
145+
});
146+
}));
147+
it(`should not be set for discoverable items`, fakeAsync(() => {
148+
(headTagService as any).processRouteChange({
149+
data: {
150+
value: {
151+
dso: createSuccessfulRemoteDataObject(ItemMock),
152+
},
153+
},
154+
});
155+
tick();
156+
expect(meta.addTag).not.toHaveBeenCalledWith({
157+
name: 'robots',
158+
content: 'noindex',
159+
});
160+
}));
161+
});
162+
131163
it('items page should set meta tags', fakeAsync(() => {
132164
(headTagService as any).processRouteChange({
133165
data: {

src/app/core/metadata/head-tag.service.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ export class HeadTagService {
173173

174174
protected setDSOMetaTags(): void {
175175

176+
this.setNoIndexTag();
177+
176178
this.setTitleTag();
177179
this.setDescriptionTag();
178180

@@ -210,6 +212,15 @@ export class HeadTagService {
210212

211213
}
212214

215+
/**
216+
* Add <meta name="robots" content="noindex"> to the <head> if non-discoverable item
217+
*/
218+
protected setNoIndexTag(): void {
219+
if (this.currentObject.value instanceof Item && this.currentObject.value.isDiscoverable === false) {
220+
this.addMetaTag('robots', 'noindex');
221+
}
222+
}
223+
213224
/**
214225
* Add <meta name="title" ... > to the <head>
215226
*/

src/app/shared/mocks/item.mock.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,4 +293,55 @@ export const ItemMock: Item = Object.assign(new Item(), {
293293
},
294294
),
295295
});
296+
297+
export const NonDiscoverableItemMock: Item = Object.assign(new Item(), {
298+
handle: '10673/7',
299+
lastModified: '2017-04-24T19:44:08.178+0000',
300+
isArchived: true,
301+
isDiscoverable: false,
302+
isWithdrawn: false,
303+
bundles: createSuccessfulRemoteDataObject$(createPaginatedList([
304+
MockOriginalBundle,
305+
])),
306+
_links:{
307+
self: {
308+
href: 'https://dspace7.4science.it/dspace-spring-rest/api/core/items/0ec7ff22-f211-40ab-a69e-c819b0b1f358',
309+
},
310+
},
311+
id: '0ec7ff22-f211-40ab-a69e-c819b0b1f358',
312+
uuid: '0ec7ff22-f211-40ab-a69e-c819b0b1f358',
313+
type: 'item',
314+
metadata: {
315+
'dc.date.accessioned': [
316+
{
317+
language: null,
318+
value: '1650-06-26T19:58:25Z',
319+
},
320+
],
321+
'dc.date.available': [
322+
{
323+
language: null,
324+
value: '1650-06-26T19:58:25Z',
325+
},
326+
],
327+
'dc.date.issued': [
328+
{
329+
language: null,
330+
value: '1650-06-26',
331+
},
332+
],
333+
'dc.identifier.uri': [
334+
{
335+
language: null,
336+
value: 'http://dspace7.4science.it/xmlui/handle/10673/7',
337+
},
338+
],
339+
'dc.title': [
340+
{
341+
language: 'en_US',
342+
value: 'Test Non-Discoverable',
343+
},
344+
],
345+
},
346+
});
296347
/* eslint-enable @typescript-eslint/no-shadow */

0 commit comments

Comments
 (0)