mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
- Issue URL → github.com/luxfi/explore - API docs links → docs.lux.network - Contract verification → local route instead of vera.blockscout.com - Discord link → discord.gg/luxnetwork - JSON-LD script ID → lux-explorer-product-schema - RPC API description → Lux Network branding - Rollbar instance → .lux.network domain support
36 lines
1.2 KiB
TypeScript
36 lines
1.2 KiB
TypeScript
import type { ApiData } from './types';
|
|
import type { RouteParams } from 'nextjs/types';
|
|
|
|
import type { Route } from 'nextjs-routes';
|
|
|
|
import generate from './generate';
|
|
|
|
const JSON_LD_SCRIPT_ID = 'lux-explorer-product-schema';
|
|
|
|
export default function update<Pathname extends Route['pathname']>(route: RouteParams<Pathname>, apiData: ApiData<Pathname>) {
|
|
const { title, description, jsonLd } = generate(route, apiData);
|
|
|
|
window.document.title = title;
|
|
window.document.querySelector('meta[name="description"]')?.setAttribute('content', description);
|
|
|
|
// Update or create JSON-LD script tag for Product schema
|
|
if (jsonLd) {
|
|
let scriptElement = window.document.getElementById(JSON_LD_SCRIPT_ID) as HTMLScriptElement | null;
|
|
|
|
if (!scriptElement) {
|
|
scriptElement = window.document.createElement('script');
|
|
scriptElement.id = JSON_LD_SCRIPT_ID;
|
|
scriptElement.type = 'application/ld+json';
|
|
window.document.head.appendChild(scriptElement);
|
|
}
|
|
|
|
scriptElement.textContent = JSON.stringify(jsonLd);
|
|
} else {
|
|
// Remove JSON-LD script if it exists but schema is not needed
|
|
const existingScript = window.document.getElementById(JSON_LD_SCRIPT_ID);
|
|
if (existingScript) {
|
|
existingScript.remove();
|
|
}
|
|
}
|
|
}
|