Skip to content

Commit 5bb3060

Browse files
[DSC-1433] add OpenGraph and Twitter image card tags to setDSOMetaTags()
1 parent b207e74 commit 5bb3060

1 file changed

Lines changed: 63 additions & 60 deletions

File tree

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

Lines changed: 63 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,11 @@ export class MetadataService {
208208

209209
this.setOpenGraphTitleTag();
210210
this.setOpenGraphDescriptionTag();
211-
//this.setOpenGraphImageTag();
211+
this.setOpenGraphImageTag();
212212

213213
this.setTwitterTitleTag();
214214
this.setTwitterDescriptionTag();
215-
//this.setTwitterImageTag();
215+
this.setTwitterImageTag();
216216
}
217217

218218
/**
@@ -408,22 +408,75 @@ export class MetadataService {
408408
* Add <meta name="citation_pdf_url" ... > to the <head>
409409
*/
410410
private setCitationPdfUrlTag(): void {
411+
this.setSocialImageTag('ORIGINAL', 'citation_pdf_url');
412+
}
413+
414+
/**
415+
* Add <meta name="og:title" ... > to the <head>
416+
*/
417+
private setOpenGraphTitleTag(): void {
418+
const value = this.getMetaTagValue('dc.title');
419+
this.addMetaTag('og:title', value);
420+
}
421+
422+
/**
423+
* Add <meta name="og:description" ... > to the <head>
424+
*/
425+
private setOpenGraphDescriptionTag(): void {
426+
// TODO: truncate abstract
427+
const value = this.getMetaTagValue('dc.description.abstract');
428+
this.addMetaTag('og:description', value);
429+
}
430+
431+
/**
432+
* Add <meta name="og:image" ... > to the <head>
433+
*/
434+
private setOpenGraphImageTag(): void {
435+
this.setSocialImageTag('THUMBNAIL', 'og:image');
436+
}
437+
438+
439+
/**
440+
* Add <meta name="twitter:title" ... > to the <head>
441+
*/
442+
private setTwitterTitleTag(): void {
443+
const value = this.getMetaTagValue('dc.title');
444+
this.addMetaTag('twitter:title', value);
445+
}
446+
447+
/**
448+
* Add <meta name="twitter:description" ... > to the <head>
449+
*/
450+
private setTwitterDescriptionTag(): void {
451+
// TODO: truncate abstract
452+
const value = this.getMetaTagValue('dc.description.abstract');
453+
this.addMetaTag('twitter:description', value);
454+
}
455+
456+
/**
457+
* Add <meta name="twitter:image" ... > to the <head>
458+
*/
459+
private setTwitterImageTag(): void {
460+
this.setSocialImageTag('THUMBNAIL', 'twitter:image');
461+
}
462+
463+
private setSocialImageTag(bundleName: string, tag: string): void {
411464
if (this.currentObject.value instanceof Item) {
412465
const item = this.currentObject.value as Item;
413466

414-
// Retrieve the ORIGINAL bundle for the item
467+
// Retrieve the THUMBNAIL bundle for the item
415468
this.bundleDataService.findByItemAndName(
416469
item,
417-
'ORIGINAL',
470+
bundleName,
418471
true,
419472
true,
420473
followLink('primaryBitstream'),
421474
followLink('bitstreams', {
422-
findListOptions: {
423-
// limit the number of bitstreams used to find the citation pdf url to the number
424-
// shown by default on an item page
425-
elementsPerPage: this.appConfig.item.bitstream.pageSize
426-
}
475+
findListOptions: {
476+
// limit the number of bitstreams used to find the citation pdf url to the number
477+
// shown by default on an item page
478+
elementsPerPage: this.appConfig.item.bitstream.pageSize
479+
}
427480
}, followLink('format')),
428481
).pipe(
429482
getFirstSucceededRemoteDataPayload(),
@@ -467,63 +520,13 @@ export class MetadataService {
467520
).subscribe((link: string) => {
468521
// Use the found link to set the <meta> tag
469522
this.addMetaTag(
470-
'citation_pdf_url',
523+
tag,
471524
new URLCombiner(this.hardRedirectService.getCurrentOrigin(), link).toString()
472525
);
473526
});
474527
}
475528
}
476529

477-
/**
478-
* Add <meta name="og:title" ... > to the <head>
479-
*/
480-
private setOpenGraphTitleTag(): void {
481-
const value = this.getMetaTagValue('dc.title');
482-
this.addMetaTag('og:title', value);
483-
}
484-
485-
/**
486-
* Add <meta name="og:description" ... > to the <head>
487-
*/
488-
private setOpenGraphDescriptionTag(): void {
489-
// TODO: truncate abstract
490-
const value = this.getMetaTagValue('dc.description.abstract');
491-
this.addMetaTag('og:description', value);
492-
}
493-
494-
/**
495-
* Add <meta name="og:image" ... > to the <head>
496-
*/
497-
private setOpenGraphImageTag(): void {
498-
const value = '';
499-
this.addMetaTag('og:image', value);
500-
}
501-
502-
/**
503-
* Add <meta name="twitter:title" ... > to the <head>
504-
*/
505-
private setTwitterTitleTag(): void {
506-
const value = this.getMetaTagValue('dc.title');
507-
this.addMetaTag('twitter:title', value);
508-
}
509-
510-
/**
511-
* Add <meta name="twitter:description" ... > to the <head>
512-
*/
513-
private setTwitterDescriptionTag(): void {
514-
// TODO: truncate abstract
515-
const value = this.getMetaTagValue('dc.description.abstract');
516-
this.addMetaTag('twitter:description', value);
517-
}
518-
519-
/**
520-
* Add <meta name="twitter:image" ... > to the <head>
521-
*/
522-
private setTwitterImageTag(): void {
523-
const value = '';
524-
this.addMetaTag('twitter:image', value);
525-
}
526-
527530
getBitLinkIfDownloadable(bitstream: Bitstream, bitstreamRd: RemoteData<PaginatedList<Bitstream>>): Observable<string> {
528531
return observableOf(bitstream).pipe(
529532
getDownloadableBitstream(this.authorizationService),

0 commit comments

Comments
 (0)