2021-04-12 19:38:30 +02:00
|
|
|
class blogFooter extends HTMLElement {
|
2022-03-25 10:13:32 +01:00
|
|
|
connectedCallback(){
|
2022-03-08 12:06:56 +01:00
|
|
|
this.getBlogEntries();
|
|
|
|
}
|
2021-04-18 21:49:25 +02:00
|
|
|
|
2022-03-08 12:06:56 +01:00
|
|
|
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-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);
|
|
|
|
});
|
2021-04-12 19:38:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
customElements.define("jl-footer_blog", blogFooter);
|