buddyscloud/assets/js/dynamic-tdk.js

25 lines
860 B
JavaScript

// static/js/dynamic-tdk.js
export function updateTDK(tdk) {
document.title = tdk.title;
let metaDescription = document.querySelector('meta[name="description"]');
if (metaDescription) {
metaDescription.setAttribute('content', tdk.description);
} else {
metaDescription = document.createElement('meta');
metaDescription.setAttribute('name', 'description');
metaDescription.setAttribute('content', tdk.description);
document.head.appendChild(metaDescription);
}
let metaKeywords = document.querySelector('meta[name="keywords"]');
if (metaKeywords) {
metaKeywords.setAttribute('content', tdk.keywords);
} else {
metaKeywords = document.createElement('meta');
metaKeywords.setAttribute('name', 'keywords');
metaKeywords.setAttribute('content', tdk.keywords);
document.head.appendChild(metaKeywords);
}
}