embedingHF's picture
Upload folder using huggingface_hub
84fc8e7 verified
Raw
History Blame Contribute Delete
2.5 kB
/**
* Premium SEO Dynamic Header and Schema Manager
* Enhances search engine indexing, click-through rates, and Google ranking signals.
*/
export interface SEOConfig {
title: string;
description: string;
keywords: string;
schema?: string;
canonicalUrl?: string;
}
export function updateSEO({ title, description, keywords, schema, canonicalUrl }: SEOConfig) {
// Update document title
document.title = title;
// Update or create Meta Description
let metaDesc = document.querySelector('meta[name="description"]');
if (!metaDesc) {
metaDesc = document.createElement("meta");
metaDesc.setAttribute("name", "description");
document.head.appendChild(metaDesc);
}
metaDesc.setAttribute("content", description);
// Update or create Meta Keywords
let metaKeywords = document.querySelector('meta[name="keywords"]');
if (!metaKeywords) {
metaKeywords = document.createElement("meta");
metaKeywords.setAttribute("name", "keywords");
document.head.appendChild(metaKeywords);
}
metaKeywords.setAttribute("content", keywords);
// Open Graph Facebook/LinkedIn tags
let ogTitle = document.querySelector('meta[property="og:title"]');
if (!ogTitle) {
ogTitle = document.createElement("meta");
ogTitle.setAttribute("property", "og:title");
document.head.appendChild(ogTitle);
}
ogTitle.setAttribute("content", title);
let ogDesc = document.querySelector('meta[property="og:description"]');
if (!ogDesc) {
ogDesc = document.createElement("meta");
ogDesc.setAttribute("property", "og:description");
document.head.appendChild(ogDesc);
}
ogDesc.setAttribute("content", description);
// Canonical URL Link
const fullUrl = canonicalUrl || window.location.href;
let linkCanonical = document.querySelector('link[rel="canonical"]');
if (!linkCanonical) {
linkCanonical = document.createElement("link");
linkCanonical.setAttribute("rel", "canonical");
document.head.appendChild(linkCanonical);
}
linkCanonical.setAttribute("href", fullUrl);
// Structured Data Schema markup for rich snippet display
let schemaScript = document.getElementById("lumina-structured-data");
if (schemaScript) {
schemaScript.remove();
}
if (schema) {
schemaScript = document.createElement("script");
schemaScript.id = "lumina-structured-data";
schemaScript.setAttribute("type", "application/ld+json");
schemaScript.innerHTML = schema;
document.head.appendChild(schemaScript);
}
}