diff --git a/assets/scripts/comments.js b/assets/scripts/comments.js index 1c4c772..6abb4fc 100755 --- a/assets/scripts/comments.js +++ b/assets/scripts/comments.js @@ -36,6 +36,7 @@ function createComment(comment) { const wrapper = document.createElement("div"); wrapper.className = "comment"; wrapper.dataset.id = comment.id; + wrapper.id = `comment-${comment.id}`; const author = document.createElement("strong"); author.textContent = comment.author || "Anonymous"; diff --git a/assets/scripts/zhd.js b/assets/scripts/zhd.js index 83f83d2..d636b68 100755 --- a/assets/scripts/zhd.js +++ b/assets/scripts/zhd.js @@ -144,6 +144,12 @@ return comment.created_at || comment.createdAt || ""; } + function commentHref(page, comment) { + if (!page?.url) return null; + if (!comment.id) return page.url + "#comments"; + return page.url + "#comment-" + encodeURIComponent(comment.id); + } + function formatCommentDate(value) { const date = new Date(value); if (Number.isNaN(date.getTime())) return ""; @@ -182,7 +188,7 @@ const slug = commentSlug(comment); const page = pageMap.get(slug); const title = page?.title || slug || "Unknown page"; - const href = page?.url ? page.url + "#comments" : null; + const href = commentHref(page, comment); const author = comment.author || "Anonymous"; const date = formatCommentDate(commentDate(comment)); const pageLink = href