From 2f3e49890628318f5f9261a2bbd12bda63f1789f Mon Sep 17 00:00:00 2001 From: Mononaut Date: Thu, 9 Mar 2023 00:26:28 -0600 Subject: [PATCH] fix canonical/meta tags in unfurler --- unfurler/src/index.ts | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/unfurler/src/index.ts b/unfurler/src/index.ts index 90938a5a8..412dd0f4c 100644 --- a/unfurler/src/index.ts +++ b/unfurler/src/index.ts @@ -27,6 +27,7 @@ class Server { mempoolUrl: URL; network: string; secureHost = true; + canonicalHost: string; constructor() { this.app = express(); @@ -34,6 +35,20 @@ class Server { this.mempoolUrl = new URL(this.mempoolHost); this.secureHost = config.SERVER.HOST.startsWith('https'); this.network = config.MEMPOOL.NETWORK || 'bitcoin'; + + let canonical; + switch(config.MEMPOOL.NETWORK) { + case "liquid": + canonical = "https://liquid.network" + break; + case "bisq": + canonical = "https://bisq.markets" + break; + default: + canonical = "https://mempool.space" + } + this.canonicalHost = canonical; + this.startServer(); } @@ -259,6 +274,8 @@ class Server { let ogImageUrl = config.SERVER.HOST + (matchedRoute.staticImg || matchedRoute.fallbackImg); let ogTitle = 'The Mempool Open Source Project™'; + const canonical = this.canonicalHost + rawPath; + if (matchedRoute.render) { ogImageUrl = `${config.SERVER.HOST}/render/${lang || 'en'}/preview${path}`; ogTitle = `${this.network ? capitalize(this.network) + ' ' : ''}${matchedRoute.networkMode !== 'mainnet' ? capitalize(matchedRoute.networkMode) + ' ' : ''}${matchedRoute.title}`; @@ -269,6 +286,7 @@ class Server { ${ogTitle} + @@ -291,7 +309,8 @@ class Server { let html = await this.ssrCluster?.execute({ url: this.mempoolHost + rawPath, path: rawPath, action: 'ssr' }); // remove javascript to prevent double hydration if (html && html.length) { - html = html.replace(//g, ""); + html = html.replaceAll(//g, ""); + html = html.replaceAll(this.mempoolHost, this.canonicalHost); } return html; }