cassidy,
@cassidy@blaede.family avatar

I’ve promised enough people this, so I had to do it! 😁

Here’s my write-up of how I added client-side Fediverse-powered comments to my Jekyll blog using the Mastodon API.

Huge props to @jwildeboer for the initial inspiration, as well as @julian and everyone who provided feedback for inspiring the design improvements.

https://cassidyjames.com/blog/fediverse-blog-comments-mastodon/

✨💬 Reply to this thread then check the blog post comments to see it in action!

cassidy,
@cassidy@blaede.family avatar

Well this thread went absolutely nuts. Thanks to everyone who tested things out! I’ll have to write an update or a follow-up post, but after a way-too-late-night hacking session, my implementation now supports:

• Better configuration options
• More reusable OP/verified badging
• Link cards
• Spoilers/content warnings

Check the thread on this post itself for examples of each! https://cassidyjames.com/blog/fediverse-blog-comments-mastodon/#comments

cassidy,
@cassidy@blaede.family avatar

Hm, we hit the default limit for a single Mastodon API call… it looks like I have to figure out how to handle HTTP headers and perform follow-up API calls to grab more than 60 replies!

Thanks to everyone in this thread stress-testing with me; I’ll get it sorted out. :)

cassidy, (edited )
@cassidy@blaede.family avatar

Unfortunately, it appears to be an intentional, undocumented limit for unauthenticated API calls to the context endpoint… however, including an authentication token would require me making people sign in to view more comments, or leaking a token that would enable people to read my private statuses.

I’ve reported this to Mastodon here: https://github.com/mastodon/mastodon/issues/25892

Please 👍 the issue, but don’t just comment “me too!” type comments on the issue.

knu,
@knu@toot.community avatar

@cassidy
I don't know if this is a "me too" type comment, but, undocumented or not, to me it looks like a sensible protection against DoS attacks.

cassidy,
@cassidy@blaede.family avatar

@knu I meant folks shouldn't comment "me too!" on the linked issue; discussing whatever here is fine. 😃

Yeah I understand why it would have some limiting… it's just frustrating that it was entirely undocumented AND the only ways to provide authentication client-side would either require folks to log into a Mastodon account or for me to leak my own private statuses…

This may just lead me to build the thread at build time which is a lot more work and necessitates storing folks' posts in my repo.

cassidy,
@cassidy@blaede.family avatar

@knu I guess it should be totally possible to use a dedicated bot account without any statuses to authenticate the API without leaking private statuses. It basically undoes the DoS protection, though, as anyone could find that access token.

It’s what I’ve pushed to my site for now, though!

knu,
@knu@toot.community avatar

@cassidy At least DoS attack by a bot (or its stolen access token) can be stopped by the admin of the attacked server, by disabling the account. (just my 0.02, I have little experience)

cassidy, (edited )
@cassidy@blaede.family avatar

Good news, everyone! I’ve added support for an access token to my code which means we’re back in business.

For those who want to re-use the code, creating a token requires a dedicated bot account on your origin Mastodon server unless you want to leak your private statuses. And using the token effectively lets anyone make authenticated API calls, though harm should be relatively limited.

It’s better than nothing—and if omitted, you’ll still get 60 replies as before.

https://github.com/cassidyjames/cassidyjames.github.io/pull/57

cassidy,
@cassidy@blaede.family avatar

Has this gotten out of hand? Almost certainly! That said, comments on my site now ALSO support:

• Edited indication
• Displaying boosts
• Displaying images and GIFs

See it in action: https://cassidyjames.com/blog/fediverse-blog-comments-mastodon/#comments

poppacalypse,
@poppacalypse@alpaca.gold avatar

@cassidy damn son! 😃

fantinel,
@fantinel@hachyderm.io avatar

@cassidy soo how long until you have a fully featured Jekyll Mastodon client? 😄

cassidy,
@cassidy@blaede.family avatar

@fantinel yeah forreeal. I kind of want a client with this styling!

justin,
@justin@toot.io avatar

@cassidy
Feature
.
.
.
.
CREEP!

openroomxyz,

@cassidy does this mean it will be like Twitter ?

mathieucomandon,
@mathieucomandon@fosstodon.org avatar

@cassidy subscribe to Mastodon Blue to increase your API call rate to 600 replies? 🤷

cassidy,
@cassidy@blaede.family avatar

@mathieucomandon ha no it’s definitely a “me” problem! By default, the status/context API call seems to limit the response to 60 replies, because that is a LOT of data to send in a single request—each API response is basically a document not just of the content of the replies, but of everything you would need to make a social media client app. So every user’s public profile is included with every post, including all their links and their full bio and links to all the images for all emoji, etc.

cassidy,
@cassidy@blaede.family avatar

@mathieucomandon however, the API helpfully includes a pointer to the next “page” of results in the header of its response if the response is limited… my code just doesn’t handle that response at all yet. 😅 It should be straightforward once I figure out how to actually read and process that header. I just haven't even looked into it yet.

cassidy,
@cassidy@blaede.family avatar

@mathieucomandon ha, it turns out I was wrong; it is an intentional (but undocumented) limitation of the unauthenticated API. Which makes sense, it’s a heavy API call.

I’ve reported the issue to Mastodon, proposed an update to the Mastodon API documentation, AND pushed an update to my site to use an authenticated API call. :)

mathieucomandon,
@mathieucomandon@fosstodon.org avatar

@cassidy that comment system is really cool and I'd like to give it a shot on my Pelican based blog. But if I understand correctly, you need to manage your own Mastodon instance, is that right?

cassidy,
@cassidy@blaede.family avatar

@mathieucomandon no, not at all! You can use it with any Mastodon account, and don’t even need an API key in most cases.

If you expect to have more than 60 comments on a post and/or your server has authenticated fetch enabled, then you will need to provide an API key from an account on the same server—I would recommend a throwaway/bot account because that API key will allow anyone to read THAT account’s private posts/DMs.

cassidy,
@cassidy@blaede.family avatar

@mathieucomandon I originally used “any account on my own Mastodon instance” as a sort of “verified” shortcut since I do have my own instance, but I have since changed it to distinctly style the original poster’s account, and also support an arbitrary list of “verified” accounts that can get styled distinctly.

mathieucomandon,
@mathieucomandon@fosstodon.org avatar

@cassidy that's really cool! I don't think Fosstodon would let me run a bot account but I could do it from another instance... or run my own, which is something I'm considering more and more.

cassidy,
@cassidy@blaede.family avatar

@mathieucomandon I think the bot account would have to be on the same instance, but I haven't tested that theory. But again, only needed if you expect to have more than 60 comments per post or I believe if your instance has authenticated fetch enabled (since I believe that doesn't allow unauthenticated API requests).

mathieucomandon,
@mathieucomandon@fosstodon.org avatar

@cassidy 60 posts seems to be a good default. To avoid overcrowding the blog page, I could add a "Continue the conversation on Mastodon" link when that limit is reached

cassidy,
@cassidy@blaede.family avatar

@mathieucomandon yeah that seems like a good idea!

admin,
@admin@c.im avatar

@cassidy It's super cool :ablobcathyper:

pixeltracker,
@pixeltracker@sigmoid.social avatar

Thanks again for your post and your tremendous work, @cassidy! I just implemented your code on my website ^_^ I made some minor tweaks and added the additional option to check whether a Mastodon post is associated with the blog post or not. If no Mastodon post is found (id is empty), an appropriate message will be displayed (details and code can be found here: https://www.fabriziomusacchio.com/blog/2023-07-31-mastodon_blog_comment_system/). Huge thanks again 🙏 I really love this implementation, and I'm happy to have it running on my website now 😊

alice,

@cassidy let's see :3

:blobcatstretchtop:​
:blobcatstretchmiddle:​
:blobcatstretchbottom:​

:nyancat_rainbow:​:nyancat_rainbow:​:nyancat_body:​:nyancat_face:​

:neofox_stretch_down:​:blank:​:neofox_stretch_ur:​:neofox_stretch_ul:​
:neofox_stretch_dr:​:neofox_stretch_h:​:neofox_stretch_dl:​:neofox_stretch_v:​
:blank:​:blank:​:blank:​:neofox_stretch_up:​

alice,

@cassidy pff

cassidy,
@cassidy@blaede.family avatar

@alice heh, the line height one I’m fine with; I value readability over emoji art. 😝

The missing string replacement… idk. I feel like that should have worked.

alice,

@cassidy I mean the line height is not constant, it’s just custom emoji that are larger than text :)

lgarron,
@lgarron@mastodon.social avatar

@cassidy Oooh, I love this implementation!

As a small UX thing: my first instinct was to try to figure out how to interact with this by scrolling to the very bottom of the page — but the instructions are at the top of the comments in the middle of the page. Would it be easy to duplicate the instructions / link to them, if there are enough posts to fill a few screens?

cassidy,
@cassidy@blaede.family avatar
ojensen,
@ojensen@hachyderm.io avatar

@cassidy @jwildeboer @julian well that's pretty neat :)

cassidy,
@cassidy@blaede.family avatar
mattrambles,
@mattrambles@t00t.cloud avatar

@cassidy This is really cool! Out of curiosity, did you happen to consider webmentions?

https://webmention.io

I’m only toying with different approaches and I can’t tell if a middle layer amounts to more hassle or more control (moderation, various sources) over time.

pieceofthepie,
@pieceofthepie@n8e.dev avatar

@cassidy @jwildeboer @julian and now I just need to figure out how to wrangle this into Hugo 😆

canpolat,

@cassidy Have you looked at the Lemmy API? I don't think it's as stragithforward as Mastodon, but I feel like Lemmy (and kbin) are better suited for being commenting systems.

Anyway... I think it's great that you did this and I hope this approach gets more popular among tech writers.

juiceboy,

so cool!

cassidy,
@cassidy@blaede.family avatar

@juiceboy thanks!

jaanus,

@cassidy @jwildeboer @julian @drahardja very interesting, thank you for sharing! I’m partly commenting just out of curiosity to see if my response shows up on your site 😀

jaanus,

@cassidy I don’t see it appear on the website though. Am I holding it wrong?

cassidy,
@cassidy@blaede.family avatar
cassidy,
@cassidy@blaede.family avatar

@jaanus fixed!

bhaugen,
@bhaugen@social.coop avatar

@cassidy
Ok, I am replying. Where do I see it in action? Over here?
https://cassidyjames.com/blog/

@jwildeboer @julian

cassidy,
@cassidy@blaede.family avatar

@bhaugen replies in this thread show in the comments at the bottom of the blog post linked in the first post—however, we’ve exceeded the number of replies received with a single API call, and my code doesn’t handle automatically making follow-up API calls yet. So new comments on that post aren’t showing until I fix it. 😅

https://mastodon.blaede.family/@cassidy/110676436597870047

bhaugen,
@bhaugen@social.coop avatar

@cassidy say when and how you want me and others to try it again.

cassidy,
@cassidy@blaede.family avatar

@bhaugen it should be fixed!

bhaugen,
@bhaugen@social.coop avatar

@cassidy thanks I'll try again tomorrow morning. Let me know if you want people to try any particular tests.

cassidy,
@cassidy@blaede.family avatar

@bhaugen one thing I know is missing is image/media handling. But otherwise, I think it’s fairly well tested at this point!

bhaugen,
@bhaugen@social.coop avatar

@cassidy
Ok, here's another comment.

And I now can see my previous comments in this thread, that ended up in the overflow that you fixed between my previous comments and this one.

So thanks, and good work!

I do have a blog that is somewhat connected to Fedi.
https://write.as/economic-networks/

Wonder if I could deploy your setup on that blog, which uses @write_as ?

cassidy,
@cassidy@blaede.family avatar

@bhaugen possibly, if @write_as allows arbitrary JS and CSS! I have tried to make it fairly reusable by pulling all of the Jekyll concerns out to the top to be easily replaced.

See the HTML/JS source here: https://github.com/cassidyjames/cassidyjames.github.io/blob/main/_includes/comments.html

The CSS here: https://github.com/cassidyjames/cassidyjames.github.io/blob/main/_sass/_comments.scss

And here for my config values: https://github.com/cassidyjames/cassidyjames.github.io/blob/main/_config.yaml#L30-L69

bhaugen,
@bhaugen@social.coop avatar

@matt any comments on whether the comments setup that
@cassidy created could be used at my blog on @write_as ?

cassidy,
@cassidy@blaede.family avatar

@bhaugen if you're a paid user, you could throw an invite my way to see if I can put something together. :)

cydonian,
@cydonian@vivaldi.net avatar

@cassidy @jwildeboer @julian This is awesome work! Now if it can only work on Quarto and GitHub Pages, I’ll be all set…

cassidy,
@cassidy@blaede.family avatar

@cydonian @jwildeboer @julian I'm not familiar with Quarto, but my site is using Jekyll on GitHub Pages. It should be relatively portable, though.

cydonian,
@cydonian@vivaldi.net avatar

@cassidy @jwildeboer @julian Now I have to explore this, don’t I. 😀🤷🏻‍♂️

cassidy,
@cassidy@blaede.family avatar
GeekAndDad,
@GeekAndDad@mastodon.social avatar

@cassidy Quite cool.

Seems like sooner or later you’re going to want moderation tools like blocking a user. That’s one thing that seemed missing.

cassidy,
@cassidy@blaede.family avatar

@GeekAndDad oh for sure. I think if possible, my plan is to actually use my own account for moderation if possible, e.g. if I blocked/muted someone, then hide them from the site.

Gotta figure out if I can do that with an unauthenticated API call or not though; if I need an API key, the integration gets a little more complex.

GeekAndDad,
@GeekAndDad@mastodon.social avatar

@cassidy Interesting approach. Sounds ideal if not too difficult. I was thinking you’d just have an extra button as admin and their user handle would get added to a static file that is a list of people who’s comments don’t get displayed (they halt traversal of a given tree branch so replies to their post also don’t show up). Your approach is better :)

cassidy,
@cassidy@blaede.family avatar

@GeekAndDad oh for sure, I think the static blocklist would be much simpler, especially given API tokens being involved.

I still want to think about it some more, though.

passthejoe,
@passthejoe@ruby.social avatar

deleted_by_author

  • Loading...
  • cassidy,
    @cassidy@blaede.family avatar

    @passthejoe thank you! I've spent a lot of time on the design. :D

    pixeltracker,
    @pixeltracker@sigmoid.social avatar

    Awesome work! Thanks for this
    @cassidy 🙏❤️

    cassidy,
    @cassidy@blaede.family avatar

    @pixeltracker you're welcome!

    amxmln,
    @amxmln@mastodon.design avatar

    @cassidy thanks for the more in-depth post. 😊

    I'm really wondering though if there's a way to not have to rebuild and publish the page twice, once to get the post URL to post on Mastodon and then again after adding the Mastodon post ID. 🤔

    Like you say, doing it through the build process might be the best option, but you might end up with broken links in your Mastodon posts if the process fails, or at least until the new build is published. 🤔

    cassidy,
    @cassidy@blaede.family avatar

    @amxmln yeah that's definitely the most clunky part right now. It's not the worst, but I don't love it.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • mastodon
  • DreamBathrooms
  • thenastyranch
  • tacticalgear
  • khanakhh
  • Youngstown
  • rosin
  • slotface
  • everett
  • vwfavf
  • ngwrru68w68
  • kavyap
  • ethstaker
  • mdbf
  • magazineikmin
  • megavids
  • Durango
  • modclub
  • InstantRegret
  • osvaldo12
  • GTA5RPClips
  • normalnudes
  • anitta
  • cubers
  • tester
  • cisconetworking
  • provamag3
  • Leos
  • JUstTest
  • All magazines