Integrate Mastodon as comment system into your posts #5747
Andre601
started this conversation in
Show and tell
Replies: 1 comment
-
Awesome, thanks for sharing! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Recently did I ask in the Material for MkDocs repository1 about how I could implement a Mastodon-based comment system (#5728).
After looking a bit myself did I manage to setup a working version using some blog post on how to do it.
The post giving the code snippet and explaining it was made for Hugo, so some adjustments were required to make it work.
And since there is no post addressing this for MkDocs and the Material for MkDocs theme am I making this post now.
I already posted a Paste2 with some basic instructions, but I feel like a more in-depth explanation was useful to have, so here we are.
Enjoy!
Prerequisites
To make this comment system work you need...
Limitations and issues
This setup compared to Giscuss has a few limitations.
The most annoying one is the requirement for the post to exist before your blog page...
We need a Post ID to load and displays replies from. So you either need to make a post, copy the id and add to your blog post, or make the blog post, create a Mastodon toot, copy id, edit blog post...
Another issue - at least with my aproach - is that it isn't directly compatible with Material for MkDocs' theme as in, it won't adapt itself to switching the theme.
I designed this for dark theme only, so the colours won't adjust themself.
Other Notes
During this post we will assume the following setups:
custom_dir
setting oftheme
in yourmkdocs.yml
is set totheme
example.com
and the user isExample
Step 1: Creating the files
If you haven't already, you need to extend the Material for MkDocs theme3 and create a new file in the theme extension folder.
The file we need is
comments.html
which is located inpartials/
so the full path - relative to themkdocs.yml
file - would betheme/partials/comments.html
In addition should you make a CSS file in the assets directory (i.e.
docs/assets/stylesheets/comments.css
) and add it as an entry to theextra_css
setting of yourmkdocs.yml
to get it loaded as CSS for your pages.Now open the files in a text editor of your choice...
Step 2: Adding content
You need to add some content to the
comments.html
file and thecomments.css
file.comments.html
comments.css
Final steps
What is left to do is add the necessary data to the
mkdocs.yml
file and the pages you want comments for.In the
mkdocs.yml
you need to add the following:On the pages you want to have comments enabled, you need to add these frontmatter options:
comments: true
to enable the comments feature. Only needed if you're not enabling it by default (i.e. by not including the if check in the partials file or by using the meta plugin to enable it for a folder)comment_id: <id>
with<id>
being an id to a valid post on the Mastodon instance and from the user you defined in yourmkdocs.yml
file.This should be everything and once you publish your pages (or check them in the live preview using
mkdocs serve
) should the comment system load your posts or otherwise show admonition boxes with further info.Preview
Here are some previews to show you how it may look like.
No post configured
No replies
Comment
Footnotes
https://github.com/squidfunk/mkdocs-material ↩
https://paste.gg/p/Andre601/4d1323b59c35421e90bcdc79f6ed8ff2 ↩
https://squidfunk.github.io/mkdocs-material/customization/#extending-the-theme ↩
Beta Was this translation helpful? Give feedback.
All reactions