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

Martin Kletzander mkletzan at redhat.com
Wed Jun 19 15:22:57 UTC 2019


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
we'd either need to have our own proxy, send a sss header to allow fetching the
atom.xml or providing JSONP access to the RSS feed on virt-planet.

Signed-off-by: Martin Kletzander <mkletzan at redhat.com>
---
 docs/index.html.in | 13 -------------
 docs/js/main.js    | 47 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 47 insertions(+), 13 deletions(-)

diff --git a/docs/index.html.in b/docs/index.html.in
index f593445d061d..fa75289cad0f 100644
--- a/docs/index.html.in
+++ b/docs/index.html.in
@@ -5,19 +5,6 @@
     <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'
-        })
-      })
-      // -->
-    </script>
   </head>
   <body class="index">
     <h1>The virtualization API</h1>
diff --git a/docs/js/main.js b/docs/js/main.js
index e57b9f47ac11..07f79c7ff903 100644
--- a/docs/js/main.js
+++ b/docs/js/main.js
@@ -29,6 +29,53 @@ function pageload() {
 
     simpleSearch = document.getElementById("simplesearch")
     simplesearch.addEventListener("submit", advancedsearch)
+
+    docLoc = document.location;
+    if (docLoc.protocol != "file:" ||
+        docLoc.origin != "null" ||
+        docLoc.host !== "" ||
+        docLoc.hostname !== "") {
+        fetchRSS()
+    }
+}
+
+function fetchRSS() {
+    cb = "jsonpRSSFeedCallback"
+    window["jsonpRSSFeedCallback"] = function (data) {
+        if (data.responseStatus != 200)
+            return
+        entries = data.responseData.feed.entries
+        nEntries = Math.min(entries.length, 4)
+
+        dl = document.createElement('dl')
+
+        dateOpts = { day: 'numeric', month: 'short', year: 'numeric'}
+
+        for (i = 0; i < nEntries; i++) {
+            entry = entries[i]
+            a = document.createElement('a')
+            a.href = entry.link
+            a.innerText = entry.title
+
+            dt = document.createElement('dt')
+            dt.appendChild(a)
+            dl.appendChild(dt)
+
+            date = new Date(entry.publishedDate)
+            datestr = date.toLocaleDateString('default', dateOpts)
+
+            dd = document.createElement('dd')
+            dd.innerText = ` by ${entry.author} on ${datestr}`
+
+            dl.appendChild(dd)
+        }
+
+        planet.appendChild(dl);
+    };
+    script = document.createElement("script")
+    script.src = "https://feedrapp.herokuapp.com/"
+    script.src += `?q=http%3A%2F%2Fplanet.virt-tools.org%2Fatom.xml&callback=${cb}`
+    document.body.appendChild(script);
 }
 
 function advancedsearch(e) {
-- 
2.21.0




More information about the libvir-list mailing list