From 9a66205d80d2888b9ac3c9d823f3416a340ba8dc Mon Sep 17 00:00:00 2001 From: Alex Selimov Date: Mon, 3 Aug 2026 23:38:33 -0400 Subject: [PATCH] Update top posts and upvote to pass/get title --- static/top_posts.js | 19 ++++--------------- static/upvote.js | 4 ++++ 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/static/top_posts.js b/static/top_posts.js index 2f560f3..224b2cf 100644 --- a/static/top_posts.js +++ b/static/top_posts.js @@ -14,27 +14,16 @@ for (post of data) { const postUrl = post.slug.replace("posts-", ""); const pageUrl = `/posts/${postUrl}`; + const title = post.title; - try { - const pageResponse = await fetch(pageUrl); - const html = await pageResponse.text(); - const doc = new DOMParser().parseFromString(html, "text/html"); - const title = - doc.querySelector('meta[property="og:title"]')?.content || - doc.title || - slug; + const li = document.createElement("li"); - const li = document.createElement("li"); - - li.innerHTML = ` + li.innerHTML = ` ${title} `; - ul.appendChild(li); - } catch (err) { - console.error(err); - } + ul.appendChild(li); } })(); diff --git a/static/upvote.js b/static/upvote.js index 131da67..ee45491 100644 --- a/static/upvote.js +++ b/static/upvote.js @@ -19,8 +19,12 @@ const alreadyVoted = btn.hasAttribute("voted"); const method = alreadyVoted ? "DELETE" : "POST"; + const r = await fetch(`${API}/posts/${slug}/vote`, { method, + body: JSON.stringify({ + title: document.querySelector('meta[name="title"]').content, + }), credentials: "include", });