-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds opengraph to records with specific component
- Loading branch information
Showing
7 changed files
with
82 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,15 @@ | ||
import { Component, OnInit } from '@angular/core' | ||
import { getThemeConfig } from '@geonetwork-ui/util/app-config' | ||
import { ThemeService } from '@geonetwork-ui/util/shared' | ||
import { Meta } from '@angular/platform-browser' | ||
|
||
@Component({ | ||
selector: 'datahub-root', | ||
templateUrl: './app.component.html', | ||
styleUrls: ['./app.component.css'], | ||
}) | ||
export class AppComponent implements OnInit { | ||
constructor(private meta: Meta) {} | ||
|
||
ngOnInit(): void { | ||
const favicon = getThemeConfig().FAVICON | ||
if (favicon) ThemeService.setFavicon(favicon) | ||
this.meta.updateTag({ property: 'og:url', content: window.location.origin }) | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
apps/datahub/src/app/record/record-page/record-page.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 3 additions & 38 deletions
41
apps/datahub/src/app/record/record-page/record-page.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,26 @@ | ||
import { | ||
ChangeDetectionStrategy, | ||
Component, | ||
OnDestroy, | ||
OnInit, | ||
} from '@angular/core' | ||
import { ChangeDetectionStrategy, Component, OnDestroy } from '@angular/core' | ||
import { MdViewFacade } from '@geonetwork-ui/feature/record' | ||
import { Meta } from '@angular/platform-browser' | ||
import { | ||
MetadataQualityConfig, | ||
getMetadataQualityConfig, | ||
} from '@geonetwork-ui/util/app-config' | ||
import { Subscription } from 'rxjs' | ||
|
||
@Component({ | ||
selector: 'datahub-record-page', | ||
templateUrl: './record-page.component.html', | ||
styleUrls: ['./record-page.component.css'], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class RecordPageComponent implements OnDestroy, OnInit { | ||
export class RecordPageComponent implements OnDestroy { | ||
metadataQualityDisplay: boolean | ||
sub: Subscription | ||
|
||
constructor(public mdViewFacade: MdViewFacade, private meta: Meta) { | ||
constructor(public mdViewFacade: MdViewFacade) { | ||
document.documentElement.classList.add('record-page-active') | ||
const cfg: MetadataQualityConfig = | ||
getMetadataQualityConfig() || ({} as MetadataQualityConfig) | ||
this.metadataQualityDisplay = cfg.ENABLED | ||
} | ||
ngOnDestroy() { | ||
document.documentElement.classList.remove('record-page-active') | ||
this.meta.updateTag({ property: 'og:title', content: 'Datahub' }) | ||
this.meta.updateTag({ | ||
property: 'og:url', | ||
content: window.location.href.toString(), | ||
}) | ||
this.meta.removeTag('property="og:image"') | ||
this.sub.unsubscribe() | ||
} | ||
|
||
ngOnInit(): void { | ||
this.sub = this.mdViewFacade.metadata$.subscribe((metadata) => { | ||
if (metadata) { | ||
this.meta.updateTag({ property: 'og:title', content: metadata.title }) | ||
this.meta.updateTag({ | ||
property: 'og:url', | ||
content: window.location.href.toString(), | ||
}) | ||
if (metadata.overviews.length > 0) { | ||
for (const overview of metadata.overviews) { | ||
this.meta.addTag({ | ||
property: 'og:image', | ||
content: overview.url.toString(), | ||
}) | ||
} | ||
} | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
libs/feature/record/src/lib/record-meta/record-meta.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing' | ||
import { RecordMetaComponent } from './record-meta.component' | ||
|
||
describe('ExternalViewerButtonComponent', () => { | ||
let component: RecordMetaComponent | ||
let fixture: ComponentFixture<RecordMetaComponent> | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
declarations: [RecordMetaComponent], | ||
imports: [], | ||
providers: [], | ||
}).compileComponents() | ||
}) | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(RecordMetaComponent) | ||
component = fixture.componentInstance | ||
}) | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy() | ||
}) | ||
}) |
48 changes: 48 additions & 0 deletions
48
libs/feature/record/src/lib/record-meta/record-meta.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { | ||
AfterViewInit, | ||
ChangeDetectionStrategy, | ||
Component, | ||
Input, | ||
OnChanges, | ||
OnDestroy, | ||
} from '@angular/core' | ||
import { Meta } from '@angular/platform-browser' | ||
import { | ||
DatasetRecord, | ||
ServiceRecord, | ||
} from '@geonetwork-ui/common/domain/model/record' | ||
|
||
@Component({ | ||
selector: 'gn-ui-record-meta', | ||
template: '<>', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class RecordMetaComponent implements OnDestroy, OnChanges { | ||
@Input() metadata: DatasetRecord | ||
|
||
constructor(private meta: Meta) {} | ||
|
||
ngOnChanges() { | ||
if (this.metadata?.title) { | ||
this.meta.addTag({ property: 'og:title', content: this.metadata.title }) | ||
this.meta.addTag({ | ||
property: 'og:url', | ||
content: window.location.href.toString(), | ||
}) | ||
if (this.metadata?.overviews?.length > 0) { | ||
for (const overview of this.metadata.overviews) { | ||
this.meta.addTag({ | ||
property: 'og:image', | ||
content: overview.url.toString(), | ||
}) | ||
} | ||
} | ||
} | ||
} | ||
|
||
ngOnDestroy() { | ||
this.meta.removeTag('property="og:image"') | ||
this.meta.removeTag('property="og:url"') | ||
this.meta.removeTag('property="og:title"') | ||
} | ||
} |