From b207e74f47d6db1fea0a9c5a195d29e646be9a46 Mon Sep 17 00:00:00 2001 From: "yevhenii.lohatskyi" <lohatskyi.yevhenii@4science.com> Date: Tue, 16 Jan 2024 10:00:44 +0200 Subject: [PATCH 1/5] [DSC-1433] add OpenGraph and Twitter card tags to setDSOMetaTags() --- src/app/core/metadata/metadata.service.ts | 57 +++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/src/app/core/metadata/metadata.service.ts b/src/app/core/metadata/metadata.service.ts index 0c13b94c749..e76ee2425a0 100644 --- a/src/app/core/metadata/metadata.service.ts +++ b/src/app/core/metadata/metadata.service.ts @@ -206,6 +206,13 @@ export class MetadataService { this.setCitationTechnicalReportNumberTag(); } + this.setOpenGraphTitleTag(); + this.setOpenGraphDescriptionTag(); + //this.setOpenGraphImageTag(); + + this.setTwitterTitleTag(); + this.setTwitterDescriptionTag(); + //this.setTwitterImageTag(); } /** @@ -467,6 +474,56 @@ export class MetadataService { } } + /** + * Add <meta name="og:title" ... > to the <head> + */ + private setOpenGraphTitleTag(): void { + const value = this.getMetaTagValue('dc.title'); + this.addMetaTag('og:title', value); + } + + /** + * Add <meta name="og:description" ... > to the <head> + */ + private setOpenGraphDescriptionTag(): void { + // TODO: truncate abstract + const value = this.getMetaTagValue('dc.description.abstract'); + this.addMetaTag('og:description', value); + } + + /** + * Add <meta name="og:image" ... > to the <head> + */ + private setOpenGraphImageTag(): void { + const value = ''; + this.addMetaTag('og:image', value); + } + + /** + * Add <meta name="twitter:title" ... > to the <head> + */ + private setTwitterTitleTag(): void { + const value = this.getMetaTagValue('dc.title'); + this.addMetaTag('twitter:title', value); + } + + /** + * Add <meta name="twitter:description" ... > to the <head> + */ + private setTwitterDescriptionTag(): void { + // TODO: truncate abstract + const value = this.getMetaTagValue('dc.description.abstract'); + this.addMetaTag('twitter:description', value); + } + + /** + * Add <meta name="twitter:image" ... > to the <head> + */ + private setTwitterImageTag(): void { + const value = ''; + this.addMetaTag('twitter:image', value); + } + getBitLinkIfDownloadable(bitstream: Bitstream, bitstreamRd: RemoteData<PaginatedList<Bitstream>>): Observable<string> { return observableOf(bitstream).pipe( getDownloadableBitstream(this.authorizationService), From 5bb3060f7d4760bd066e07013086d3465ba804e6 Mon Sep 17 00:00:00 2001 From: "yevhenii.lohatskyi" <lohatskyi.yevhenii@4science.com> Date: Tue, 16 Jan 2024 17:47:37 +0200 Subject: [PATCH 2/5] [DSC-1433] add OpenGraph and Twitter image card tags to setDSOMetaTags() --- src/app/core/metadata/metadata.service.ts | 123 +++++++++++----------- 1 file changed, 63 insertions(+), 60 deletions(-) diff --git a/src/app/core/metadata/metadata.service.ts b/src/app/core/metadata/metadata.service.ts index e76ee2425a0..9850c89210c 100644 --- a/src/app/core/metadata/metadata.service.ts +++ b/src/app/core/metadata/metadata.service.ts @@ -208,11 +208,11 @@ export class MetadataService { this.setOpenGraphTitleTag(); this.setOpenGraphDescriptionTag(); - //this.setOpenGraphImageTag(); + this.setOpenGraphImageTag(); this.setTwitterTitleTag(); this.setTwitterDescriptionTag(); - //this.setTwitterImageTag(); + this.setTwitterImageTag(); } /** @@ -408,22 +408,75 @@ export class MetadataService { * Add <meta name="citation_pdf_url" ... > to the <head> */ private setCitationPdfUrlTag(): void { + this.setSocialImageTag('ORIGINAL', 'citation_pdf_url'); + } + + /** + * Add <meta name="og:title" ... > to the <head> + */ + private setOpenGraphTitleTag(): void { + const value = this.getMetaTagValue('dc.title'); + this.addMetaTag('og:title', value); + } + + /** + * Add <meta name="og:description" ... > to the <head> + */ + private setOpenGraphDescriptionTag(): void { + // TODO: truncate abstract + const value = this.getMetaTagValue('dc.description.abstract'); + this.addMetaTag('og:description', value); + } + + /** + * Add <meta name="og:image" ... > to the <head> + */ + private setOpenGraphImageTag(): void { + this.setSocialImageTag('THUMBNAIL', 'og:image'); + } + + + /** + * Add <meta name="twitter:title" ... > to the <head> + */ + private setTwitterTitleTag(): void { + const value = this.getMetaTagValue('dc.title'); + this.addMetaTag('twitter:title', value); + } + + /** + * Add <meta name="twitter:description" ... > to the <head> + */ + private setTwitterDescriptionTag(): void { + // TODO: truncate abstract + const value = this.getMetaTagValue('dc.description.abstract'); + this.addMetaTag('twitter:description', value); + } + + /** + * Add <meta name="twitter:image" ... > to the <head> + */ + private setTwitterImageTag(): void { + this.setSocialImageTag('THUMBNAIL', 'twitter:image'); + } + + private setSocialImageTag(bundleName: string, tag: string): void { if (this.currentObject.value instanceof Item) { const item = this.currentObject.value as Item; - // Retrieve the ORIGINAL bundle for the item + // Retrieve the THUMBNAIL bundle for the item this.bundleDataService.findByItemAndName( item, - 'ORIGINAL', + bundleName, true, true, followLink('primaryBitstream'), followLink('bitstreams', { - findListOptions: { - // limit the number of bitstreams used to find the citation pdf url to the number - // shown by default on an item page - elementsPerPage: this.appConfig.item.bitstream.pageSize - } + findListOptions: { + // limit the number of bitstreams used to find the citation pdf url to the number + // shown by default on an item page + elementsPerPage: this.appConfig.item.bitstream.pageSize + } }, followLink('format')), ).pipe( getFirstSucceededRemoteDataPayload(), @@ -467,63 +520,13 @@ export class MetadataService { ).subscribe((link: string) => { // Use the found link to set the <meta> tag this.addMetaTag( - 'citation_pdf_url', + tag, new URLCombiner(this.hardRedirectService.getCurrentOrigin(), link).toString() ); }); } } - /** - * Add <meta name="og:title" ... > to the <head> - */ - private setOpenGraphTitleTag(): void { - const value = this.getMetaTagValue('dc.title'); - this.addMetaTag('og:title', value); - } - - /** - * Add <meta name="og:description" ... > to the <head> - */ - private setOpenGraphDescriptionTag(): void { - // TODO: truncate abstract - const value = this.getMetaTagValue('dc.description.abstract'); - this.addMetaTag('og:description', value); - } - - /** - * Add <meta name="og:image" ... > to the <head> - */ - private setOpenGraphImageTag(): void { - const value = ''; - this.addMetaTag('og:image', value); - } - - /** - * Add <meta name="twitter:title" ... > to the <head> - */ - private setTwitterTitleTag(): void { - const value = this.getMetaTagValue('dc.title'); - this.addMetaTag('twitter:title', value); - } - - /** - * Add <meta name="twitter:description" ... > to the <head> - */ - private setTwitterDescriptionTag(): void { - // TODO: truncate abstract - const value = this.getMetaTagValue('dc.description.abstract'); - this.addMetaTag('twitter:description', value); - } - - /** - * Add <meta name="twitter:image" ... > to the <head> - */ - private setTwitterImageTag(): void { - const value = ''; - this.addMetaTag('twitter:image', value); - } - getBitLinkIfDownloadable(bitstream: Bitstream, bitstreamRd: RemoteData<PaginatedList<Bitstream>>): Observable<string> { return observableOf(bitstream).pipe( getDownloadableBitstream(this.authorizationService), From 13ac71bed419759570cce1f8552411b8937c6486 Mon Sep 17 00:00:00 2001 From: "yevhenii.lohatskyi" <lohatskyi.yevhenii@4science.com> Date: Tue, 16 Jan 2024 17:51:49 +0200 Subject: [PATCH 3/5] [DSC-1433] fix small comment error --- src/app/core/metadata/metadata.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/core/metadata/metadata.service.ts b/src/app/core/metadata/metadata.service.ts index 9850c89210c..579517c6f50 100644 --- a/src/app/core/metadata/metadata.service.ts +++ b/src/app/core/metadata/metadata.service.ts @@ -464,7 +464,7 @@ export class MetadataService { if (this.currentObject.value instanceof Item) { const item = this.currentObject.value as Item; - // Retrieve the THUMBNAIL bundle for the item + // Retrieve the bundle for the item this.bundleDataService.findByItemAndName( item, bundleName, From d7abd74d186ed83dcd4c47a4ff83a04de07297b0 Mon Sep 17 00:00:00 2001 From: Vlad Nouski <uladzislau.nouski@4science.com> Date: Tue, 16 Jan 2024 14:28:57 +0100 Subject: [PATCH 4/5] [DSC-1486] feature: added check to main tab --- src/app/item-page/cris-item-page-tab.resolver.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/app/item-page/cris-item-page-tab.resolver.ts b/src/app/item-page/cris-item-page-tab.resolver.ts index aaca1568572..b381a993664 100644 --- a/src/app/item-page/cris-item-page-tab.resolver.ts +++ b/src/app/item-page/cris-item-page-tab.resolver.ts @@ -54,7 +54,11 @@ export class CrisItemPageTabResolver implements Resolve<RemoteData<PaginatedList const givenTab = urlSplit[1]; const itemPageRoute = getItemPageRoute(itemRD.payload); const isValidTab = tabsRD.payload.page.some((tab) => !givenTab || `/${tab.shortname}` === givenTab); - const mainTab = tabsRD.payload.page.filter((tab) => !tab.leading)[0]; + + const mainTab = tabsRD.payload.page.length === 1 + ? tabsRD.payload.page[0] + : tabsRD.payload.page.find(tab => !tab.leading); + if (!isValidTab) { // If wrong tab is given redirect to 404 page this.router.navigateByUrl(getPageNotFoundRoute(), { skipLocationChange: true, replaceUrl: false }); From 6dd31538c638dfe4e69bc1e53654f03c6da62681 Mon Sep 17 00:00:00 2001 From: Daniele Ninfo <daniele.ninfo@4science.com> Date: Thu, 8 Feb 2024 19:21:12 +0100 Subject: [PATCH 5/5] [DSC-1433] Modified the method name setSocialImageTag in setPrimaryBitstreamInBundleTag --- src/app/core/metadata/metadata.service.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/app/core/metadata/metadata.service.ts b/src/app/core/metadata/metadata.service.ts index 579517c6f50..9e27ce5cf00 100644 --- a/src/app/core/metadata/metadata.service.ts +++ b/src/app/core/metadata/metadata.service.ts @@ -408,7 +408,7 @@ export class MetadataService { * Add <meta name="citation_pdf_url" ... > to the <head> */ private setCitationPdfUrlTag(): void { - this.setSocialImageTag('ORIGINAL', 'citation_pdf_url'); + this.setPrimaryBitstreamInBundleTag('ORIGINAL', 'citation_pdf_url'); } /** @@ -432,7 +432,7 @@ export class MetadataService { * Add <meta name="og:image" ... > to the <head> */ private setOpenGraphImageTag(): void { - this.setSocialImageTag('THUMBNAIL', 'og:image'); + this.setPrimaryBitstreamInBundleTag('THUMBNAIL', 'og:image'); } @@ -457,10 +457,10 @@ export class MetadataService { * Add <meta name="twitter:image" ... > to the <head> */ private setTwitterImageTag(): void { - this.setSocialImageTag('THUMBNAIL', 'twitter:image'); + this.setPrimaryBitstreamInBundleTag('THUMBNAIL', 'twitter:image'); } - private setSocialImageTag(bundleName: string, tag: string): void { + private setPrimaryBitstreamInBundleTag(bundleName: string, tag: string): void { if (this.currentObject.value instanceof Item) { const item = this.currentObject.value as Item;