aggiunta sezione per articoli in evidenza

This commit is contained in:
giomba 2021-02-15 23:01:15 +01:00
parent ca4cab59f7
commit 357d303bfb
3 changed files with 32 additions and 5 deletions

View File

@ -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");

View File

@ -56,12 +56,16 @@
<section id="news" class="bg">
<h2>News</h2>
<div>
<h3>In evidenza</h3>
<ul id="wp-featured-posts"></ul>
</div>
<div>
<h3>Calendario</h3>
<ul id="zerocalcare-latest-events"></ul>
</div>
<div>
<h3>Ultimi post</h3>
<h3>Ultimi articoli</h3>
<ul id="wp-latest-posts"></ul>
</div>
<div>

View File

@ -85,7 +85,7 @@ section#news {
}
@media (min-width: 800px) {
section#news > div {
width: 33%;
width: 24%;
}
}