Add comments

This commit is contained in:
Nathan McCarty 2025-02-12 21:26:00 -05:00
parent b307eb391b
commit 4de44c7e8c
3 changed files with 388 additions and 6 deletions

View file

@ -13,9 +13,20 @@ unit class Config;
method generate-post(Int:D $id, Post:D $post, $db) {
my $meta = $db.meta;
my $content = $post.render-html;
my $cactus-script = qq
document.addEventListener('DOMContentLoaded', () => \{
initComments(\{
node: document.getElementById("comment-section"),
defaultHomeserverUrl: "https://matrix.cactus.chat",
serverName: "cactus.chat",
siteName: "stranger.systems",
commentSectionId: "post-$id"
\})\})」;
my $head =
head [
# Generate the universal header components
generate-head($meta, $post.title, $post.description);
# Open graph tags for embedding
meta :property<og:title>, :content($post.title);
meta :property<og:url>, :content(post-link-abs $db.meta, $id, $post);
meta :property<og:site_name>, :content($db.meta.title);
@ -26,6 +37,14 @@ method generate-post(Int:D $id, Post:D $post, $db) {
$post.tags.map(-> $tag {
meta :property<article:tag>, :content($tag)
});
# Cactus comments support
link :rel<stylesheet>,
:href</resources/cactus.css>,
:type<text/css>;
script :src<https://gateway.pinata.cloud/ipfs/QmSiWN27KZZ1XE32jKwifBnS3nWTUcFGNArKzur2nmDgoL/v0.13.0/cactus.js>;
# Only actually load the script if the post isn't hidden
optl !$post.hidden, -> {script $cactus-script};
];
my $body =
body [
@ -34,8 +53,10 @@ method generate-post(Int:D $id, Post:D $post, $db) {
post-header $id, $post, $db;
div :class<post-body>, [
$content;
]
]
];
];
# Only actually have the comment section if the post isn't hidden
optl !$post.hidden, -> {div :id<comment-section>, :class<comments>};
];
# TODO: Setup Comments
# TODO: Setup footer

View file

@ -159,10 +159,11 @@ class PostDB {
mkdir $res-dir unless $res-dir.e;
# symlink the resources directory to make "interactive" styling eaiser
# TODO: Directories support
%?RESOURCES<colors.css>.IO.symlink: $res-dir.add('colors.css') unless %?RESOURCES<colors.css>.IO.e;
%?RESOURCES<main.css>.IO.symlink: $res-dir.add('main.css') unless %?RESOURCES<main.css>.IO.e;
%?RESOURCES<code.css>.IO.symlink: $res-dir.add('code.css') unless %?RESOURCES<code.css>.IO.e;
%?RESOURCES<admonitions.css>.IO.symlink: $res-dir.add('admonitions.css') unless %?RESOURCES<admonitions.css>.IO.e;
%?RESOURCES<colors.css>.IO.symlink: $res-dir.add('colors.css') unless $res-dir.add('colors.css').e;
%?RESOURCES<main.css>.IO.symlink: $res-dir.add('main.css') unless $res-dir.add('main.css').e;
%?RESOURCES<code.css>.IO.symlink: $res-dir.add('code.css') unless $res-dir.add('code.css').e;
%?RESOURCES<admonitions.css>.IO.symlink: $res-dir.add('admonitions.css') unless $res-dir.add('admonitions.css').e;
%?RESOURCES<cactus.css>.IO.symlink: $res-dir.add('cactus.css') unless $res-dir.add('cactus.css').e;
}
#| Get a list of posts sorted by date