Skip to content

Commit

Permalink
feat: adds opengraph to records (#1042)
Browse files Browse the repository at this point in the history
  • Loading branch information
f-necas authored Nov 19, 2024
1 parent a2b8f0d commit fdac73d
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 0 deletions.
2 changes: 2 additions & 0 deletions apps/datahub/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
FeatureRecordModule,
GN_UI_VERSION,
WEB_COMPONENT_EMBEDDER_URL,
RecordMetaComponent,
} from '@geonetwork-ui/feature/record'
import {
DefaultRouterModule,
Expand Down Expand Up @@ -188,6 +189,7 @@ export const metaReducers: MetaReducer[] = !environment.production ? [] : []
CarouselComponent,
BlockListComponent,
PreviousNextButtonsComponent,
RecordMetaComponent,
LetDirective,
// FIXME: these imports are required by non-standalone components and should be removed once all components have been made standalone
NgIconsModule.withIcons({
Expand Down
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
1 change: 1 addition & 0 deletions libs/feature/record/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export * from './lib/data-view-share/data-view-share.component'
export * from './lib/data-view-web-component/data-view-web-component.component'
export * from './lib/external-viewer-button/external-viewer-button.component'
export * from './lib/map-view/map-view.component'
export * from './lib/record-meta/record-meta.component'
1 change: 1 addition & 0 deletions libs/feature/record/src/lib/feature-record.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ import { matClose, matOpenInNew } from '@ng-icons/material-icons/baseline'
DataViewPermalinkComponent,
DataViewWebComponentComponent,
DataViewShareComponent,
ExternalViewerButtonComponent,
],
})
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('RecordMetaComponent', () => {
let component: RecordMetaComponent
let fixture: ComponentFixture<RecordMetaComponent>

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [],
imports: [RecordMetaComponent],
providers: [],
}).compileComponents()
})

beforeEach(() => {
fixture = TestBed.createComponent(RecordMetaComponent)
component = fixture.componentInstance
})

it('should create', () => {
expect(component).toBeTruthy()
})
})
45 changes: 45 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,45 @@
import {
ChangeDetectionStrategy,
Component,
Input,
OnChanges,
OnDestroy,
} from '@angular/core'
import { Meta } from '@angular/platform-browser'
import { DatasetRecord } from '@geonetwork-ui/common/domain/model/record'

@Component({
selector: 'gn-ui-record-meta',
template: '',
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
})
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"')
}
}

0 comments on commit fdac73d

Please sign in to comment.