Skip to content

Commit c677e3e

Browse files
Andrea Barbassoatarix83
authored andcommitted
Merged in task/dspace-cris-2023_02_x/DSC-2168 (pull request DSpace#2902)
[DSC-2168] fix adding multiple meta tags to the item page Approved-by: Giuseppe Digilio
2 parents 74c17e7 + 243fa16 commit c677e3e

3 files changed

Lines changed: 25 additions & 10 deletions

File tree

src/app/core/metadata/metadata.service.spec.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ describe('MetadataService', () => {
8383
meta = jasmine.createSpyObj('meta', {
8484
updateTag: {},
8585
addTag: {},
86-
removeTag: {}
86+
removeTag: {},
87+
removeTagElement: {},
88+
getTags: ['1', '2'],
8789
});
8890
title = jasmine.createSpyObj({
8991
setTitle: {}
@@ -156,7 +158,8 @@ describe('MetadataService', () => {
156158
name: 'citation_title',
157159
content: 'Test PowerPoint Document',
158160
});
159-
expect(meta.updateTag).toHaveBeenCalledWith({ name: 'citation_author', content: 'Doe, Jane' });
161+
expect(meta.addTag).toHaveBeenCalledWith({ name: 'citation_author', content: 'Doe, Jane' });
162+
expect(meta.addTag).toHaveBeenCalledWith({ name: 'citation_author', content: 'Doe, John' });
160163
expect(meta.updateTag).toHaveBeenCalledWith({
161164
name: 'citation_publication_date',
162165
content: '1650-06-26',
@@ -169,6 +172,13 @@ describe('MetadataService', () => {
169172
});
170173
}));
171174

175+
it('items page should remove multiple tags', fakeAsync(() => {
176+
metadataService.clearMetaTags();
177+
expect(meta.getTags).toHaveBeenCalledWith('name="title"');
178+
expect(meta.getTags).toHaveBeenCalledWith('name="description"');
179+
expect(meta.removeTagElement).toHaveBeenCalledTimes(4);
180+
}));
181+
172182
it('items page should set meta tags as published Thesis', fakeAsync(() => {
173183
(metadataService as any).processRouteChange({
174184
data: {

src/app/core/metadata/metadata.service.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,7 @@ export class MetadataService {
268268
* Add <meta name="citation_author" ... > to the <head>
269269
*/
270270
private setCitationAuthorTags(): void {
271-
// limit author to first 20 entries to avoid issue with item page rendering
272-
const values: string[] = this.getMetaTagValues(['dc.author', 'dc.contributor.author', 'dc.creator'])
273-
.slice(0, this.appConfig.item.metatagLimit);
271+
const values: string[] = this.getMetaTagValues(['dc.author', 'dc.contributor.author', 'dc.creator']);
274272
this.addMetaTags('citation_author', values);
275273
}
276274

@@ -720,18 +718,19 @@ export class MetadataService {
720718
return this.currentObject.value.allMetadataValues(keys);
721719
}
722720

723-
protected addMetaTag(name: string, content: string, isProperty = false): void {
721+
protected addMetaTag(name: string, content: string, isProperty = false, isMultiple = false): void {
724722
if (content) {
725723
const tag = isProperty ? { name, property: name, content } as MetaDefinition
726724
: { name, content } as MetaDefinition;
727-
this.meta.updateTag(tag);
725+
isMultiple ? this.meta.addTag(tag) : this.meta.updateTag(tag);
728726
this.storeTag(name);
729727
}
730728
}
731729

732730
private addMetaTags(name: string, content: string[]): void {
733-
for (const value of content) {
734-
this.addMetaTag(name, value);
731+
// limit meta tags with the same name to avoid issues with page rendering
732+
for (const value of content.slice(0, this.appConfig.item.metatagLimit)) {
733+
this.addMetaTag(name, value, false, true);
735734
}
736735
}
737736

@@ -746,7 +745,9 @@ export class MetadataService {
746745
take(1)
747746
).subscribe((tagsInUse: string[]) => {
748747
for (const name of tagsInUse) {
749-
this.meta.updateTag({name, content: ''});
748+
this.meta.getTags(`name="${name}"`).forEach((tag) => {
749+
this.meta.removeTagElement(tag);
750+
});
750751
}
751752
this.store.dispatch(new ClearMetaTagAction());
752753
});

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@ export const ItemMock: Item = Object.assign(new Item(), {
182182
{
183183
language: 'en_US',
184184
value: 'Doe, Jane'
185+
},
186+
{
187+
language: 'en_US',
188+
value: 'Doe, John'
185189
}
186190
],
187191
'dc.date.accessioned': [

0 commit comments

Comments
 (0)