hugo-bearcub/static/top_posts.js

29 lines
681 B
JavaScript

(async function () {
console.log("Starting top_posts");
const API = window.UPVOTE_API;
const NUM_BEST = window.NUM_BEST;
const res = await fetch(`${API}/posts/best?top=${NUM_BEST}`, {
credentials: "include",
});
const data = await res.json();
const URL = window.location.origin;
const ul = document.getElementById("top-posts");
for (post of data) {
const postUrl = post.slug.replace("posts-", "");
const pageUrl = `/posts/${postUrl}`;
const title = post.title;
const li = document.createElement("li");
li.innerHTML = `
<a href="/posts/${postUrl}">
${title}
</a>
`;
ul.appendChild(li);
}
})();