Skip to content

Commit 4be7fa9

Browse files
author
Andrea Barbasso
committed
[DSC-2168] fix adding multiple meta tags to the item page
1 parent 4982559 commit 4be7fa9

2 files changed

Lines changed: 12 additions & 10 deletions

File tree

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ describe('MetadataService', () => {
8383
meta = jasmine.createSpyObj('meta', {
8484
updateTag: {},
8585
addTag: {},
86-
removeTag: {}
86+
removeTag: {},
87+
getTags: [],
8788
});
8889
title = jasmine.createSpyObj({
8990
setTitle: {}
@@ -156,7 +157,7 @@ describe('MetadataService', () => {
156157
name: 'citation_title',
157158
content: 'Test PowerPoint Document',
158159
});
159-
expect(meta.updateTag).toHaveBeenCalledWith({ name: 'citation_author', content: 'Doe, Jane' });
160+
expect(meta.addTag).toHaveBeenCalledWith({ name: 'citation_author', content: 'Doe, Jane' });
160161
expect(meta.updateTag).toHaveBeenCalledWith({
161162
name: 'citation_publication_date',
162163
content: '1650-06-26',

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
});

0 commit comments

Comments
 (0)