Skip to content

Commit

Permalink
Add comments link and focus comment box when clicked
Browse files Browse the repository at this point in the history
  • Loading branch information
tylermercer committed Feb 7, 2025
1 parent 6d92b40 commit 9c5a049
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/components/LinkCard.astro
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ const permalink = `/links/${getLinkSlug(l)}`;
<time datetime={getLinkDate(l.slug).toISOString()}>
{formatPostDate(getLinkDate(l.slug))}
</time>
</a> &middot;{" "}
<a href={permalink + "#comments"}>
No comments
</a>
</p>
</article>
Expand Down
11 changes: 11 additions & 0 deletions src/layouts/Base.astro
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,16 @@ const description = unMarkdown(descriptionRaw);

footnotesSection.appendChild(details);
}

// Focus the comment box
if (window.location.hash === "#comments") {
requestAnimationFrame(() => {
(
document.querySelector(
"label.jc-CommentBox-label > textarea",
) as HTMLTextAreaElement | null
)?.focus();
});
}
});
</script>
6 changes: 6 additions & 0 deletions src/pages/links/[slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,9 @@ const { entry } = Astro.props;
}
}
</style>

<style lang="scss" is:global>
html:has(#comments:target) {
scroll-behavior: smooth;
}
</style>

0 comments on commit 9c5a049

Please sign in to comment.