[libvirt] [PATCH v2 2/3] docs: Use our own implementation for fetching the RSS data
Martin Kletzander
mkletzan at redhat.com
Thu Jun 20 10:24:04 UTC 2019
On Thu, Jun 20, 2019 at 11:43:26AM +0200, Martin Kletzander wrote:
>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 at redhat.com>
>---
> 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";
Oh, this needs to be 'http' instead of 'https'. The feedrapp returns an error
otherwise. Fixed in my current branch.
>+ 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 at redhat.com
>https://www.redhat.com/mailman/listinfo/libvir-list
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20190620/b2931ab1/attachment-0001.sig>
More information about the libvir-list
mailing list