website/js/customElements/blogFooter.js

32 lines
1,009 B
JavaScript
Raw Normal View History

class blogFooter extends HTMLElement {
connectedCallback(){
this.getBlogEntries();
}
async getBlogEntries() {
let ul = document.createElement("ul");
this.appendChild(ul);
var graphql = JSON.stringify({
2022-03-08 12:19:39 +01:00
query: 'query($count: Int!) { blogPosts(count: $count) { title id }}',
variables: {
"count": 5
}
})
var requestOptions = {
method: 'POST',
body: graphql,
2022-04-07 09:24:06 +02:00
headers: { 'Content-Type': 'application/json' }
2022-03-08 12:19:39 +01:00
};
2022-03-15 08:49:36 +01:00
let posts = (await (await fetch("/API/graphql.php", requestOptions)).json()).data.blogPosts;
2022-03-08 12:19:39 +01:00
posts.forEach((element) => {
let li = document.createElement("li");
let a = document.createElement("a");
a.href = "/post.html?id=" + element["id"];
a.innerText = element["title"];
li.appendChild(a);
ul.appendChild(li);
});
}
}
customElements.define("jl-footer_blog", blogFooter);