Skip to content

Commit

Permalink
Merge branch 'dspace-cris-2023_02_x' into main-cris
Browse files Browse the repository at this point in the history
  • Loading branch information
atarix83 committed Feb 9, 2024
2 parents 0d2b3d4 + 8c1700d commit 8249d00
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 9 deletions.
76 changes: 68 additions & 8 deletions src/app/core/metadata/metadata.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,13 @@ export class MetadataService {
this.setCitationTechnicalReportNumberTag();
}

this.setOpenGraphTitleTag();
this.setOpenGraphDescriptionTag();
this.setOpenGraphImageTag();

this.setTwitterTitleTag();
this.setTwitterDescriptionTag();
this.setTwitterImageTag();
}

/**
Expand Down Expand Up @@ -401,22 +408,75 @@ export class MetadataService {
* Add <meta name="citation_pdf_url" ... > to the <head>
*/
private setCitationPdfUrlTag(): void {
this.setPrimaryBitstreamInBundleTag('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.setPrimaryBitstreamInBundleTag('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.setPrimaryBitstreamInBundleTag('THUMBNAIL', 'twitter:image');
}

private setPrimaryBitstreamInBundleTag(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 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(),
Expand Down Expand Up @@ -460,7 +520,7 @@ 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()
);
});
Expand Down
6 changes: 5 additions & 1 deletion src/app/item-page/cris-item-page-tab.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down

0 comments on commit 8249d00

Please sign in to comment.