Diferencia entre revisiones de «MediaWiki:Common.js»
De Enciclopedia Católica
| Línea 1: | Línea 1: | ||
| − | /* | + | /* Script completo para cargar Parse.ly y metadatos enriquecidos */ |
document.addEventListener('DOMContentLoaded', function () { | document.addEventListener('DOMContentLoaded', function () { | ||
| − | // Cargar | + | // Cargar Parse.ly |
(function(w, d) { | (function(w, d) { | ||
w.Parsely = w.Parsely || function() { | w.Parsely = w.Parsely || function() { | ||
| Línea 14: | Línea 14: | ||
})(window, document); | })(window, document); | ||
| − | // Insertar JSON-LD | + | // Insertar JSON-LD solo si MediaWiki está disponible |
if (typeof mw !== 'undefined') { | if (typeof mw !== 'undefined') { | ||
mw.loader.using('mediawiki.util', function () { | mw.loader.using('mediawiki.util', function () { | ||
| − | + | const namespace = mw.config.get('wgNamespaceNumber'); | |
| + | const title = mw.config.get('wgTitle'); | ||
| + | const url = window.location.href; | ||
| + | const datePublished = new Date(document.lastModified).toISOString(); | ||
| + | const categories = mw.config.get('wgCategories') || []; | ||
| + | const isMainPage = mw.config.get('wgIsMainPage'); | ||
| − | + | // Asignar tipo según si es portada o artículo | |
| − | + | const type = isMainPage ? "WebSite" : "NewsArticle"; | |
| − | + | ||
| − | + | // Usar categorías si existen, o 'General' | |
| + | const section = categories.length ? categories[0] : "General"; | ||
| + | const keywords = categories; | ||
| + | |||
| + | // JSON-LD enriquecido | ||
| + | const metadata = { | ||
"@context": "http://schema.org", | "@context": "http://schema.org", | ||
| − | "@type": | + | "@type": type, |
"headline": title, | "headline": title, | ||
"url": url, | "url": url, | ||
"author": { "name": "Enciclopedia Católica" }, | "author": { "name": "Enciclopedia Católica" }, | ||
"datePublished": datePublished, | "datePublished": datePublished, | ||
| − | "articleSection": " | + | "articleSection": section, |
| + | "keywords": keywords, | ||
| + | "publisher": { | ||
| + | "@type": "Organization", | ||
| + | "name": "ACI Prensa", | ||
| + | "logo": { | ||
| + | "@type": "ImageObject", | ||
| + | "url": "https://ec.aciprensa.com/newwiki/images/ACI_logo.png" | ||
| + | } | ||
| + | }, | ||
| + | "mainEntityOfPage": url | ||
}; | }; | ||
| − | + | const script = document.createElement('script'); | |
| − | + | script.type = 'application/ld+json'; | |
| − | + | script.text = JSON.stringify(metadata); | |
| − | document.head.appendChild( | + | document.head.appendChild(script); |
| − | console.log("✅ JSON-LD | + | console.log("✅ JSON-LD inserted by Common.js →", metadata); |
}); | }); | ||
} | } | ||
}); | }); | ||
Revisión de 23:38 21 may 2025
/* Script completo para cargar Parse.ly y metadatos enriquecidos */
document.addEventListener('DOMContentLoaded', function () {
// Cargar Parse.ly
(function(w, d) {
w.Parsely = w.Parsely || function() {
(w.Parsely.q = w.Parsely.q || []).push(arguments);
};
var s = d.createElement('script');
s.async = true;
s.src = 'https://cdn.parsely.com/keys/ec.aciprensa.com/p.js';
var x = d.getElementsByTagName('script')[0];
x.parentNode.insertBefore(s, x);
})(window, document);
// Insertar JSON-LD solo si MediaWiki está disponible
if (typeof mw !== 'undefined') {
mw.loader.using('mediawiki.util', function () {
const namespace = mw.config.get('wgNamespaceNumber');
const title = mw.config.get('wgTitle');
const url = window.location.href;
const datePublished = new Date(document.lastModified).toISOString();
const categories = mw.config.get('wgCategories') || [];
const isMainPage = mw.config.get('wgIsMainPage');
// Asignar tipo según si es portada o artículo
const type = isMainPage ? "WebSite" : "NewsArticle";
// Usar categorías si existen, o 'General'
const section = categories.length ? categories[0] : "General";
const keywords = categories;
// JSON-LD enriquecido
const metadata = {
"@context": "http://schema.org",
"@type": type,
"headline": title,
"url": url,
"author": { "name": "Enciclopedia Católica" },
"datePublished": datePublished,
"articleSection": section,
"keywords": keywords,
"publisher": {
"@type": "Organization",
"name": "ACI Prensa",
"logo": {
"@type": "ImageObject",
"url": "https://ec.aciprensa.com/newwiki/images/ACI_logo.png"
}
},
"mainEntityOfPage": url
};
const script = document.createElement('script');
script.type = 'application/ld+json';
script.text = JSON.stringify(metadata);
document.head.appendChild(script);
console.log("✅ JSON-LD inserted by Common.js →", metadata);
});
}
});
