Diferencia entre revisiones de «MediaWiki:Common.js»
De Enciclopedia Católica
| Línea 1: | Línea 1: | ||
| − | /* | + | /* Cargar Parse.ly y metadatos JSON-LD para todos los usuarios */ |
| − | |||
document.addEventListener('DOMContentLoaded', function () { | document.addEventListener('DOMContentLoaded', function () { | ||
| − | // Cargar el script de Parse.ly | + | // Cargar el script de Parse.ly correctamente |
| − | (function( | + | (function(w, d) { |
| − | + | w.Parsely = w.Parsely || function() { | |
| − | + | (w.Parsely.q = w.Parsely.q || []).push(arguments); | |
| − | + | }; | |
| − | + | var s = d.createElement('script'); | |
| − | })(window, document | + | 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 | + | // Insertar JSON-LD en artículos (namespace 0) |
if (typeof mw !== 'undefined') { | if (typeof mw !== 'undefined') { | ||
mw.loader.using('mediawiki.util', function () { | mw.loader.using('mediawiki.util', function () { | ||
| Línea 30: | Línea 33: | ||
}; | }; | ||
| − | var | + | var jsonLd = document.createElement('script'); |
| − | + | jsonLd.type = 'application/ld+json'; | |
| − | + | jsonLd.text = JSON.stringify(metadata); | |
| − | document.head.appendChild( | + | document.head.appendChild(jsonLd); |
console.log("✅ JSON-LD metadata inserted by Common.js"); | console.log("✅ JSON-LD metadata inserted by Common.js"); | ||
Revisión de 23:25 21 may 2025
/* Cargar Parse.ly y metadatos JSON-LD para todos los usuarios */
document.addEventListener('DOMContentLoaded', function () {
// Cargar el script de Parse.ly correctamente
(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 en artículos (namespace 0)
if (typeof mw !== 'undefined') {
mw.loader.using('mediawiki.util', function () {
if (mw.config.get('wgNamespaceNumber') !== 0) return;
var title = mw.config.get('wgTitle');
var url = window.location.href;
var datePublished = new Date(document.lastModified).toISOString();
var metadata = {
"@context": "http://schema.org",
"@type": "NewsArticle",
"headline": title,
"url": url,
"author": { "name": "Enciclopedia Católica" },
"datePublished": datePublished,
"articleSection": "General"
};
var jsonLd = document.createElement('script');
jsonLd.type = 'application/ld+json';
jsonLd.text = JSON.stringify(metadata);
document.head.appendChild(jsonLd);
console.log("✅ JSON-LD metadata inserted by Common.js");
});
}
});
