Diferencia entre revisiones de «MediaWiki:Common.js»
De Enciclopedia Católica
Línea 1: | Línea 1: | ||
/* Cualquier código JavaScript escrito aquí se cargará para todos los usuarios en cada carga de página */ | /* Cualquier código JavaScript escrito aquí se cargará para todos los usuarios en cada carga de página */ | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | (function () { | + | // Esperar que el DOM esté completamente cargado |
− | + | document.addEventListener('DOMContentLoaded', function () { | |
+ | // Cargar el script de Parse.ly | ||
+ | (function(s,p,a,r,s,e,l){ | ||
+ | s['Parsely']=r;s[r]=s[r]||function(){(s[r].q=s[r].q||[]).push(arguments)}; | ||
+ | e=p.createElement(a);l=p.getElementsByTagName(a)[0]; | ||
+ | e.async=1;e.src='https://cdn.parsely.com/keys/ec.aciprensa.com/p.js'; | ||
+ | l.parentNode.insertBefore(e,l); | ||
+ | })(window, document, 'script', 'parsely'); | ||
− | mw.loader.using('mediawiki.util', function () { | + | // Insertar metadatos JSON-LD solo 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 script = document.createElement('script'); | |
− | + | script.type = 'application/ld+json'; | |
− | + | script.text = JSON.stringify(metadata); | |
− | + | document.head.appendChild(script); | |
− | + | console.log("✅ JSON-LD metadata inserted by Common.js"); | |
− | + | }); | |
− | } | + | } |
+ | }); |
Revisión de 23:24 21 may 2025
/* Cualquier código JavaScript escrito aquí se cargará para todos los usuarios en cada carga de página */ // Esperar que el DOM esté completamente cargado document.addEventListener('DOMContentLoaded', function () { // Cargar el script de Parse.ly (function(s,p,a,r,s,e,l){ s['Parsely']=r;s[r]=s[r]||function(){(s[r].q=s[r].q||[]).push(arguments)}; e=p.createElement(a);l=p.getElementsByTagName(a)[0]; e.async=1;e.src='https://cdn.parsely.com/keys/ec.aciprensa.com/p.js'; l.parentNode.insertBefore(e,l); })(window, document, 'script', 'parsely'); // Insertar metadatos JSON-LD solo 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 script = document.createElement('script'); script.type = 'application/ld+json'; script.text = JSON.stringify(metadata); document.head.appendChild(script); console.log("✅ JSON-LD metadata inserted by Common.js"); }); } });