From 357d303bfb82ae7274cb132a27a3ac3cb52a784b Mon Sep 17 00:00:00 2001 From: giomba Date: Mon, 15 Feb 2021 23:01:15 +0100 Subject: [PATCH] aggiunta sezione per articoli in evidenza --- counters.js | 29 ++++++++++++++++++++++++++--- index.html | 6 +++++- style.css | 2 +- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/counters.js b/counters.js index ae24b0f799..73f2e55d76 100644 --- a/counters.js +++ b/counters.js @@ -141,7 +141,7 @@ function fetch_calendar() { warn.textContent = 'Errore nella connessione alle API zerocalcare.'; console.log(class_prefix+"error: "+err); ul.appendChild(warn); - });; + });; } function counters() { @@ -169,6 +169,31 @@ function counters() { }) .catch(err => console.error(err)); + fetch("https://golem.linux.it/wp/wp-json/wp/v2/posts?sticky=true") + .then(response => response.json()) + .then(json => { + let article = document.getElementById("wp-featured-posts"); + + if (json.length == 0) { + let text = document.createTextNode("Nessun articolo in evidenza"); + article.appendChild(text); + } else { + let post = json[0]; + let a = document.createElement("a"); + a.href = post.link; + a.appendChild(document.createTextNode(post.title.rendered)); + article.appendChild(a); + let text = post.excerpt.rendered.replace(/<.*?>/g, ''); + text = text.substr(0, text.indexOf('.') + 1); + text += ' [...]'; + let textNode = document.createTextNode(text); + article.appendChild(document.createElement('br')); + article.appendChild(textNode); + } + + }) + .catch(err => console.error(err)); + fetch("https://golem.linux.it/wiki/api.php?action=query&list=recentchanges&rcprop=title&rclimit=50&format=json&origin=*") .then(response => response.json()) .then(json => { @@ -193,8 +218,6 @@ function counters() { }) .catch(function(error){console.log(error);}); - - fetch("https://golem.linux.it/wp/wp-json/wp/v2/posts") .then(response => { let articles = response.headers.get("X-WP-Total"); diff --git a/index.html b/index.html index 75c4c7c0f8..dfe2c9e10b 100644 --- a/index.html +++ b/index.html @@ -56,12 +56,16 @@

News

+
+

In evidenza

+ +

Calendario

    -

    Ultimi post

    +

    Ultimi articoli

      diff --git a/style.css b/style.css index 4a16010848..fe5af2f2c9 100644 --- a/style.css +++ b/style.css @@ -85,7 +85,7 @@ section#news { } @media (min-width: 800px) { section#news > div { - width: 33%; + width: 24%; } }