Feed RSS del forum aggiunto

parent 3a2417ce
Pipeline #22716894 passed with stage
in 1 minute and 22 seconds
......@@ -102,6 +102,7 @@
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js" integrity="sha384-cs/chFZiN24E4KMATLdqdvsezGxaGsi4hLGOzlXwp5UZB1LY//20VyM2taTB4QvJ" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js" integrity="sha384-uefMccjFJAIv6A+rW+L4AHf99KvxDjWSu1z9VI8SKNVmz4sk7buKt/6v9KI65qnm" crossorigin="anonymous"></script>
<script src="static/rss.js"></script>
</body>
</html>
......@@ -7,6 +7,10 @@ layout: default
<div class="alert alert-primary" role="alert">
Questa è la nuova versione di FedoraOnLine, i nostri pinguini stanno ancora lavorando su questa pagina. Contribuisci sul <a href="https://gitlab.com/fedoraonline/fedoraonline.gitlab.io">repository GitLab</a>!
</div>
<h2>Ultime dal forum</h2>
<table class="rss table" data-src="https://forum.fedoraonline.it/extern.php?action=feed&type=rss" data-locale="it-IT" data-limit="5">
<thead><tr><th>Data</th><th>Titolo</th><th>Utente</th></tr></thead>
</table>
<h2>Cos'è Fedora?</h2>
<img class="img-fluid" src="/sites/all/themes/newfol20/images/4foundations.png" alt="4 foundations">
<p>Fedora è un sistema operativo basato sul binomio GNU/Linux ed è sviluppata dalla comunità presente in tutto il mondo, il Fedora Project.</p>
......
function removeCDATA(string) {
return string.replace("<![CDATA[", "").replace("]]>", "");
}
let containers = document.getElementsByClassName('rss');
for (let i=0; i<containers.length; i++) {
let locale = containers[i].dataset.locale;
let limit = containers[i].dataset.limit;
fetch(containers[i].dataset.src).then((res) => {
res.text().then((xmlTxt) => {
let domParser = new DOMParser();
let feed = domParser.parseFromString(xmlTxt, 'text/xml');
let items = feed.getElementsByTagName('item');
let maximum = items.length>limit ? limit : items.length;
for (let j=0; j<maximum; j++) {
let title = removeCDATA(items[j].querySelector('title').innerHTML);
let link = items[j].querySelector('link').innerHTML;
let author = items[j].querySelector('author').innerHTML.match(/\((.*)\)/)[1];
let date = new Date(items[j].querySelector('pubDate').innerHTML).toLocaleString(locale);
let row = document.createElement('tr');
row.innerHTML = `<td>${date}</td><td><a href="${link}">${title}</a></td><td>${author}</td>`;
containers[i].appendChild(row);
}
});
}).catch(() => containers[i].innerHTML = "<i>Unable to fetch RSS feed</i>");
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment