[PATCH v2 2/3] docs: Use our own implementation for fetching the RSS data

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is just a small script I wrote.  It works the same way as all the libraries
together which we are bundling, but with just JS.  The only difference is that
the day of the date is formatted as 2-digit, but this should be a bug in
Firefox (at least locally for me) as the documentation states that type
'numeric' should actually not have leading zeros.

It will not be executed when the page is loaded locally.

It also uses the same proxy that query-rss uses.  We can get rid of that, but
that's a longer-term goal than just removing the bundled JS for the next
release.

Signed-off-by: Martin Kletzander <mkletzan@xxxxxxxxxx>
---
 docs/index.html.in | 15 ++-----------
 docs/js/main.js    | 52 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+), 13 deletions(-)

diff --git a/docs/index.html.in b/docs/index.html.in
index f593445d061d..1e16f299c8fd 100644
--- a/docs/index.html.in
+++ b/docs/index.html.in
@@ -2,21 +2,10 @@
 <!DOCTYPE html>
 <html xmlns="http://www.w3.org/1999/xhtml";>
   <head>
-    <script type="text/javascript" src="js/jquery-3.1.1.min.js"> </script>
-    <script type="text/javascript" src="js/moment.min.js"> </script>
-    <script type="text/javascript" src="js/jquery.rss.min.js"> </script>
-
     <script type="text/javascript">
       <!--
-      jQuery(function($) {
-        $("#planet").rss("http://planet.virt-tools.org/atom.xml";, {
-          ssl: true,
-          layoutTemplate: '<dl>{entries}</dl>',
-          entryTemplate: '<dt><a href="{url}">{title}</a></dt><dd>by {author} on {date}</li>',
-          dateFormat: 'DD MMM YYYY'
-        })
-      })
-      // -->
+      window.addEventListener("load", function() { fetchRSS() });
+  // -->
     </script>
   </head>
   <body class="index">
diff --git a/docs/js/main.js b/docs/js/main.js
index cb424dd72fb3..b4d7f5b0d793 100644
--- a/docs/js/main.js
+++ b/docs/js/main.js
@@ -77,3 +77,55 @@ function advancedsearch(e) {
 
     return false;
 }
+
+function fetchRSS() {
+    if (document.protocol == "file:")
+        return;
+
+    var planet = document.getElementById("planet");
+    if (planet === null)
+        return;
+
+    var cb = "jsonpRSSFeedCallback";
+    window[cb] = function (data) {
+        if (data.responseStatus != 200)
+            return;
+
+        var entries = data.responseData.feed.entries;
+        var nEntries = Math.min(entries.length, 4);
+
+        var dl = document.createElement("dl");
+        var dateOpts = { day: "numeric", month: "short", year: "numeric"};
+
+        for (var i = 0; i < nEntries; i++) {
+            var entry = entries[i];
+
+            var a = document.createElement("a");
+            a.href = entry.link;
+            a.innerText = entry.title;
+
+            var dt = document.createElement("dt");
+            dt.appendChild(a);
+            dl.appendChild(dt);
+
+            var date = new Date(entry.publishedDate);
+            date = date.toLocaleDateString("default", dateOpts);
+
+            var dd = document.createElement("dd");
+            dd.innerText = ` by ${entry.author} on ${date}`;
+
+            dl.appendChild(dd);
+        }
+
+        planet.appendChild(dl);
+    };
+
+    var uri = "https://planet.virt-tools.org/atom.xml";;
+    uri = encodeURIComponent(uri);
+
+    var script = document.createElement("script");
+    script.src = "https://feedrapp.herokuapp.com/";;
+    script.src += `?q=${uri}&callback=${cb}`;
+
+    document.body.appendChild(script);
+}
-- 
2.22.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux