2026-06-15 15:49:01 -04:00
|
|
|
(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) {
|
2026-06-15 16:02:32 -04:00
|
|
|
const postUrl = post.slug.replace("posts-", "");
|
2026-06-15 15:49:01 -04:00
|
|
|
const pageUrl = `/posts/${postUrl}`;
|
2026-08-03 23:38:33 -04:00
|
|
|
const title = post.title;
|
2026-06-15 15:49:01 -04:00
|
|
|
|
2026-08-03 23:38:33 -04:00
|
|
|
const li = document.createElement("li");
|
2026-06-15 15:49:01 -04:00
|
|
|
|
2026-08-03 23:38:33 -04:00
|
|
|
li.innerHTML = `
|
2026-06-15 15:49:01 -04:00
|
|
|
<a href="/posts/${postUrl}">
|
|
|
|
|
${title}
|
|
|
|
|
|
|
|
|
|
</a>
|
|
|
|
|
`;
|
2026-08-03 23:38:33 -04:00
|
|
|
ul.appendChild(li);
|
2026-06-15 15:49:01 -04:00
|
|
|
}
|
|
|
|
|
})();
|