Herramientas personales
En la EC encontrarás artículos autorizados
sobre la fe católica
Lunes, 2 de junio de 2025

Diferencia entre revisiones de «MediaWiki:Common.js»

De Enciclopedia Católica

Saltar a: navegación, buscar
 
(No se muestran 4 ediciones intermedias del mismo usuario)
Línea 1: Línea 1:
/* Cualquier código JavaScript escrito aquí se cargará para todos los usuarios en cada carga de página */
+
/* Script completo para cargar Parse.ly y metadatos enriquecidos */
(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');
+
  
(function (w, d) {
+
document.addEventListener('DOMContentLoaded', function () {
   // Incluir el script de Parse.ly
+
   // Parse.ly loader
   (function(s,p,a,r,s,e,l){
+
   (function(w, d) {
     s['Parsely']=r;s[r]=s[r]||function(){(s[r].q=s[r].q||[]).push(arguments)};
+
     w.Parsely = w.Parsely || function() {
     e=p.createElement(a);l=p.getElementsByTagName(a)[0];
+
      (w.Parsely.q = w.Parsely.q || []).push(arguments);
     e.async=1;e.src='https://cdn.parsely.com/keys/ec.aciprensa.com/p.js';l.parentNode.insertBefore(e,l);
+
    };
   })(window, document, 'script', 'parsely');
+
     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);
  
   // Esperar que la página cargue completamente
+
   // JSON-LD + Meta + JS fallback
   mw.loader.using('mediawiki.util', function () {
+
   if (typeof mw !== 'undefined') {
    // Solo ejecutar en artículos (namespace 0)
+
    mw.loader.using('mediawiki.util', function () {
    if (mw.config.get('wgNamespaceNumber') !== 0) return;
+
      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');
  
    var title = mw.config.get('wgTitle');
+
      const type = isMainPage ? "WebSite" : "NewsArticle";
    var url = window.location.href;
+
      const section = categories.length ? categories[0] : "General";
    var author = "Desconocido"; // Puedes cambiar esto si extraes autores
+
      const keywords = categories;
    var datePublished = new Date(document.lastModified).toISOString(); // alternativa: usar un parser si tienes plantilla con fecha
+
      const author = "Enciclopedia Católica";
    var section = mw.config.get('wgCategories') || "General";
+
      const publisher = {
 +
        "@type": "Organization",
 +
        "name": "ACI Prensa",
 +
        "logo": {
 +
          "@type": "ImageObject",
 +
          "url": "https://ec.aciprensa.com/newwiki/images/ACI_logo.png"
 +
        }
 +
      };
  
    var metadata = {
+
      const metadata = {
      "@context": "http://schema.org",
+
        "@context": "http://schema.org",
      "@type": "NewsArticle",
+
        "@type": type,
      "headline": title,
+
        "headline": title,
      "url": url,
+
        "url": url,
      "author": { "name": author },
+
        "author": { "name": author },
      "datePublished": datePublished,
+
        "datePublished": datePublished,
      "articleSection": section
+
        "articleSection": section,
    };
+
        "keywords": keywords,
 +
        "publisher": publisher,
 +
        "mainEntityOfPage": url
 +
      };
 +
 
 +
      // Insert JSON-LD
 +
      const jsonLd = document.createElement('script');
 +
      jsonLd.type = 'application/ld+json';
 +
      jsonLd.text = JSON.stringify(metadata);
 +
      document.head.appendChild(jsonLd);
 +
 
 +
      // Insert <meta name="parsely-page">
 +
      const meta = document.createElement('meta');
 +
      meta.name = 'parsely-page';
 +
      meta.content = JSON.stringify({
 +
        title: title,
 +
        link: url,
 +
        type: 'post',
 +
        pub_date: datePublished,
 +
        section: section,
 +
        author: author
 +
      });
 +
      document.head.appendChild(meta);
 +
 
 +
      // JS fallback config
 +
      window.PARSELY = window.PARSELY || {};
 +
      window.PARSELY.autotrack = true;
 +
      window.PARSELY.page = {
 +
        title: title,
 +
        link: url,
 +
        type: 'post',
 +
        pub_date: datePublished,
 +
        section: section,
 +
        author: author
 +
      };
  
    var script = document.createElement('script');
+
      console.log("✅ Parse.ly: metadata inserted", {
    script.type = 'application/ld+json';
+
        jsonLd: metadata,
    script.text = JSON.stringify(metadata);
+
        parselyMeta: meta.content
     document.head.appendChild(script);
+
      });
   });
+
     });
})(window, document);
+
   }
 +
});

Última revisión de 23:46 21 may 2025

/* Script completo para cargar Parse.ly y metadatos enriquecidos */

document.addEventListener('DOMContentLoaded', function () {
  // Parse.ly loader
  (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);

  // JSON-LD + Meta + JS fallback
  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');

      const type = isMainPage ? "WebSite" : "NewsArticle";
      const section = categories.length ? categories[0] : "General";
      const keywords = categories;
      const author = "Enciclopedia Católica";
      const publisher = {
        "@type": "Organization",
        "name": "ACI Prensa",
        "logo": {
          "@type": "ImageObject",
          "url": "https://ec.aciprensa.com/newwiki/images/ACI_logo.png"
        }
      };

      const metadata = {
        "@context": "http://schema.org",
        "@type": type,
        "headline": title,
        "url": url,
        "author": { "name": author },
        "datePublished": datePublished,
        "articleSection": section,
        "keywords": keywords,
        "publisher": publisher,
        "mainEntityOfPage": url
      };

      // Insert JSON-LD
      const jsonLd = document.createElement('script');
      jsonLd.type = 'application/ld+json';
      jsonLd.text = JSON.stringify(metadata);
      document.head.appendChild(jsonLd);

      // Insert <meta name="parsely-page">
      const meta = document.createElement('meta');
      meta.name = 'parsely-page';
      meta.content = JSON.stringify({
        title: title,
        link: url,
        type: 'post',
        pub_date: datePublished,
        section: section,
        author: author
      });
      document.head.appendChild(meta);

      // JS fallback config
      window.PARSELY = window.PARSELY || {};
      window.PARSELY.autotrack = true;
      window.PARSELY.page = {
        title: title,
        link: url,
        type: 'post',
        pub_date: datePublished,
        section: section,
        author: author
      };

      console.log("✅ Parse.ly: metadata inserted", {
        jsonLd: metadata,
        parselyMeta: meta.content
      });
    });
  }
});