Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adds opengraph to records #1042

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<div id="record-page" class="overflow-hidden">
<gn-ui-record-meta
[metadata]="mdViewFacade.metadata$ | async"
></gn-ui-record-meta>
<datahub-header-record
[metadata]="mdViewFacade.metadata$ | async"
></datahub-header-record>
Expand Down
4 changes: 4 additions & 0 deletions libs/feature/record/src/lib/feature-record.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { DataViewWebComponentComponent } from './data-view-web-component/data-vi
import { DataViewShareComponent } from './data-view-share/data-view-share.component'
import { NgIconsModule, provideNgIconsConfig } from '@ng-icons/core'
import { matClose, matOpenInNew } from '@ng-icons/material-icons/baseline'
import { RecordMetaComponent } from './record-meta/record-meta.component'

@NgModule({
declarations: [
Expand All @@ -42,6 +43,7 @@ import { matClose, matOpenInNew } from '@ng-icons/material-icons/baseline'
DataViewPermalinkComponent,
DataViewWebComponentComponent,
DataViewShareComponent,
RecordMetaComponent,
],
imports: [
CommonModule,
Expand Down Expand Up @@ -79,6 +81,8 @@ import { matClose, matOpenInNew } from '@ng-icons/material-icons/baseline'
DataViewPermalinkComponent,
DataViewWebComponentComponent,
DataViewShareComponent,
ExternalViewerButtonComponent,
RecordMetaComponent,
],
})
export class FeatureRecordModule {}
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 libs/feature/record/src/lib/record-meta/record-meta.component.ts
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: '<>',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be great if you could make this component standalone, thanks!

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"')
}
}
Loading