From 368ab1dc668c52b0c0e1ca1348a0ec1312326262 Mon Sep 17 00:00:00 2001 From: Mononaut Date: Tue, 22 Aug 2023 02:54:23 +0900 Subject: [PATCH] Update canonical link with block hash --- .../src/app/bisq/bisq-block/bisq-block.component.ts | 1 + frontend/src/app/components/block/block.component.ts | 1 + frontend/src/app/services/seo.service.ts | 12 ++++++++++++ 3 files changed, 14 insertions(+) diff --git a/frontend/src/app/bisq/bisq-block/bisq-block.component.ts b/frontend/src/app/bisq/bisq-block/bisq-block.component.ts index 42f62fbc0..59bb16a9e 100644 --- a/frontend/src/app/bisq/bisq-block/bisq-block.component.ts +++ b/frontend/src/app/bisq/bisq-block/bisq-block.component.ts @@ -69,6 +69,7 @@ export class BisqBlockComponent implements OnInit, OnDestroy { this.location.replaceState( this.router.createUrlTree(['/bisq/block/', hash]).toString() ); + this.seoService.updateCanonical(this.location.path()); return this.bisqApiService.getBlock$(this.blockHash) .pipe(catchError(this.caughtHttpError.bind(this))); }), diff --git a/frontend/src/app/components/block/block.component.ts b/frontend/src/app/components/block/block.component.ts index cbe56ca15..bb83494c5 100644 --- a/frontend/src/app/components/block/block.component.ts +++ b/frontend/src/app/components/block/block.component.ts @@ -202,6 +202,7 @@ export class BlockComponent implements OnInit, OnDestroy { this.location.replaceState( this.router.createUrlTree([(this.network ? '/' + this.network : '') + '/block/', hash]).toString() ); + this.seoService.updateCanonical(this.location.path()); return this.apiService.getBlock$(hash).pipe( catchError((err) => { this.error = err; diff --git a/frontend/src/app/services/seo.service.ts b/frontend/src/app/services/seo.service.ts index 2584cbaed..3d095e1c3 100644 --- a/frontend/src/app/services/seo.service.ts +++ b/frontend/src/app/services/seo.service.ts @@ -12,6 +12,8 @@ export class SeoService { baseTitle = 'mempool'; baseDescription = 'Explore the full Bitcoin ecosystem with The Mempool Open Projectâ„¢.'; + canonicalLink: HTMLElement = document.getElementById('canonical'); + constructor( private titleService: Title, private metaService: Meta, @@ -65,6 +67,16 @@ export class SeoService { this.metaService.updateTag({ property: 'og:description', content: this.getDescription()}); } + updateCanonical(path) { + let domain = 'mempool.space'; + if (this.stateService.env.BASE_MODULE === 'liquid') { + domain = 'liquid.network'; + } else if (this.stateService.env.BASE_MODULE === 'bisq') { + domain = 'bisq.markets'; + } + this.canonicalLink.setAttribute('href', 'https://' + domain + path); + } + getTitle(): string { if (this.network === 'testnet') return this.baseTitle + ' - Bitcoin Testnet';