TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Adding comments to a static blog with Mastodon

297 点作者 ognarb超过 4 年前

19 条评论

CarelessExpert超过 4 年前
I achieve this using <a href="https:&#x2F;&#x2F;brid.gy&#x2F;" rel="nofollow">https:&#x2F;&#x2F;brid.gy&#x2F;</a> (or <a href="https:&#x2F;&#x2F;fed.brid.gy&#x2F;" rel="nofollow">https:&#x2F;&#x2F;fed.brid.gy&#x2F;</a> if you want your blog to appear as a first class member of the Fediverse), though in my case I just syndicate out to Twitter. I then collect the webmentions using <a href="https:&#x2F;&#x2F;webmention.io&#x2F;" rel="nofollow">https:&#x2F;&#x2F;webmention.io&#x2F;</a>.<p>The nice thing about this is I get a breadth of methods for receiving comments&#x2F;reactions across multiple platforms, including anything that directly supports webmention (such as <a href="https:&#x2F;&#x2F;micro.blog&#x2F;" rel="nofollow">https:&#x2F;&#x2F;micro.blog&#x2F;</a>, where my posts are also syndicated), without having to do any of the platform-specific wiring myself.
评论 #25572971 未加载
评论 #25571510 未加载
评论 #25584155 未加载
评论 #25572435 未加载
评论 #25573079 未加载
_peeley超过 4 年前
Minor (and probably not intentional) thing I like - comments are loaded manually rather than by default on page load. For more popular blogs&#x2F;sites that have comments on posts like Slate Star Codex or Less Wrong, there can be literally hundreds or thousands of comments on a single post. This makes scrolling through the post or judging the amount of content in the post via scroll bar basically impossible, but just loading comments with a button click fixes that in such a simple way.
评论 #25580920 未加载
kordlessagain超过 4 年前
I use Github Pages for my blog and just found this little gem for implementing comments using issues: <a href="https:&#x2F;&#x2F;danyow.net&#x2F;using-github-issues-for-blog-comments&#x2F;" rel="nofollow">https:&#x2F;&#x2F;danyow.net&#x2F;using-github-issues-for-blog-comments&#x2F;</a>
评论 #25575274 未加载
评论 #25576878 未加载
评论 #25580264 未加载
zdunn超过 4 年前
I like the use of the fediverse for adding comments to a blog, but this is another example of conflating mastodon with the fediverse. I&#x27;m glad OP found a solution that works for them, but I hope too many people don&#x27;t start using this technique.<p>A user could comment using any fediverse account, including Pleroma, Friendica, PixelFed, etc. Summing that up with &#x27;mastodon account&#x27; is damaging to the whole idea of the fediverse. Non-technical people might not realize that they can choose to use the other platforms.<p>Also, I hate that the mastodon API has become the de facto standard for interacting with any fediverse platform. The other platforms implemented the API to maintain compatibility with mastodon clients. Now this not-quite-standard API is controlled by a single person who doesn&#x27;t care about compatibility with other platforms.
progval超过 4 年前
<p><pre><code> document.getElementById(&#x27;mastodon-comments-list&#x27;).innerHTML = data[&#x27;descendants&#x27;].reduce(function(prev, reply) { mastodonComment = ` ... `; return prev + DOMPurify.sanitize(mastodonComment); }, &#x27;&#x27;); </code></pre> Why is it implemented like this? It looks quadratic, while it&#x27;s trivial (and more intuitive IMO) to make it linear:<p><pre><code> document.getElementById(&#x27;mastodon-comments-list&#x27;).innerHTML = data[&#x27;descendants&#x27;].map(function(reply) { return DOMPurify.sanitize(` ... `); }).join(&#x27;&#x27;);</code></pre>
评论 #25573021 未加载
评论 #25573208 未加载
评论 #25572275 未加载
llbeansandrice超过 4 年前
Do people like comments on blogs? I can&#x27;t find the links right now but I&#x27;ve found a couple of people talking about how they used to have comments on their blog and decided to get rid of it since they would occasionally become a curation&#x2F;moderation nightmare.
评论 #25579584 未加载
评论 #25575787 未加载
dmje超过 4 年前
All looked great until this: &quot;You can use your Mastodon account to reply to this post&quot; and then you lost 99% of your possible commenters
评论 #25594822 未加载
评论 #25580777 未加载
znpy超过 4 年前
Is it my impression or it&#x27;s basically impossible to do comment moderation by using Mastodon in this way?<p>Or at least harder than it should be.<p>I&#x27;d be happy to be proven wrong btw.<p>EDIT: don&#x27;t get me wrong, this is cool :)
评论 #25577911 未加载
评论 #25580953 未加载
评论 #25577769 未加载
FalconSensei超过 4 年前
What I do with Hugo is:<p>- Added reddit and twitter attributes on the frontmatter<p>- After publishing and sharing to both services, I paste reddit link&#x2F;tweet id to the frontmatter and rebuild<p>- On the blogs footer, I just embed both posts, so people can see how many replies, and also click to be redirected reply on each respective service.<p>Although I would love something more automated (and preferably with in-site response), at least this is a good flow for the readers.
评论 #25575976 未加载
unicornporn超过 4 年前
How about <a href="https:&#x2F;&#x2F;webmention.io&#x2F;" rel="nofollow">https:&#x2F;&#x2F;webmention.io&#x2F;</a> ? Fediverse-friendly and Twitter-friendly.
评论 #25573395 未加载
floatingatoll超过 4 年前
Does syndicating third-party content onto your blog in this way expose you to legal liability for publishing that content? Are deletions and takedowns synced back from Mastodon, such as when someone is taken offline for breaking local law with their Mastodon instance, or would their content remain published on your blog?
评论 #25575234 未加载
failrate超过 4 年前
&quot;One of the biggest disadvantages of static site generators is that they are static and can’t include comments.&quot; At first, I misread this as &quot;One of the biggest advantages...&quot;, and I still think that is the correct conclusion.
评论 #25576232 未加载
winrid超过 4 年前
Self plug. I run <a href="https:&#x2F;&#x2F;fastcomments.com" rel="nofollow">https:&#x2F;&#x2F;fastcomments.com</a>, which would also solve this problem, for example: <a href="https:&#x2F;&#x2F;blog.fastcomments.com&#x2F;(6-26-2020)-embedding-comments-on-github-pages.html" rel="nofollow">https:&#x2F;&#x2F;blog.fastcomments.com&#x2F;(6-26-2020)-embedding-comments...</a>
评论 #25581107 未加载
asim超过 4 年前
You can embed a comments API using micro - m3o.com. Sign-up, run the comments service, copy&#x2F;paste some JS code and there you have it.
darekkay超过 4 年前
I&#x27;ve gathered some more alternatives for static site comments on my blog [1] (ironically, I didn&#x27;t include comments on my own blog)<p>[1] <a href="https:&#x2F;&#x2F;darekkay.com&#x2F;blog&#x2F;static-site-comments&#x2F;" rel="nofollow">https:&#x2F;&#x2F;darekkay.com&#x2F;blog&#x2F;static-site-comments&#x2F;</a>
chrismorgan超过 4 年前
The technique demonstrated here for producing the markup is bad:<p>1. The use of DOMPurify is either unnecessary or insufficient. Specifically consider reply.content, which is provided from the server as HTML. (I believe it’s the only one that’s supposed to be serialised HTML; all the other fields are text.) If the backend guarantees that you get a clean DOM, DOMPurify is unnecessary†. But if it’s possible for a user to control the markup in that field completely, then DOMPurify as configured is insufficient, because although it blocks XSS and JavaScript execution, it doesn’t filter out remote resource loading and CSS, which can be almost as harmful. Trivial example, &lt;a href=&#x2F;&#x2F;malicious.example style=position:fixed;inset:0&gt;pwned&lt;&#x2F;a&gt;. Given the type of content, you probably want to either blacklist quite a few things (e.g. the style attribute, and the img, picture, source, audio and video tags), or whitelist a small set of things.<p>2. Various fields that could hypothetically contain magic characters are dropped in with no escaping. If they <i>do</i> contain magic characters like &lt; and &amp;, you’ve just messed up the display and opened the way for malicious resource loading and problem № 3 below. Even if they are supposed to be unable to contain a magic character (e.g. I’m going to <i>guess</i> that reply.account.username is safe), it’s probably a good idea to escape them anyway just in case (perhaps an API change later makes it possible), and to guard against errant copy–pasters and editors of the code that don’t know what they’re doing. Perhaps at some point you’ll add or switch to reply.account.display_name, which probably <i>can</i> contain &lt; and &amp;.<p>3. The markup is produced by mixing static templating with user-provided input, and sanitisation is performed on the whole thing. It’s important when doing this sort of templating that each user-provided input be escaped or sanitised <i>by itself in isolation</i>, not as part of a whole that has been concatenated. Otherwise you can mess with the DOM tree accidentally or deliberately. Suppose, for example, that reply.content could contain `&lt;&#x2F;div&gt;&lt;&#x2F;div&gt;&lt;&#x2F;div&gt;&lt;img src=&#x2F;&#x2F;ad.example alt=&quot;Legitimate-looking in-stream ad&quot;&gt;&lt;div class=&quot;mastodon-comment&quot;&gt;…&lt;div class=&quot;content&quot;&gt;…&lt;div class=&quot;mastodon-comment-content&quot;&gt;…`. So this means:<p>• Apply attributes and text nodes to a real DOM (e.g. `img = new Image(); img.src = reply.account.avatar_static; avatar.append(img)`), or escape them in the HTML serialisation (e.g. `&lt;img src=&quot;${reply.account.avatar_static.replace(&#x2F;&amp;&#x2F;g, &quot;&amp;amp;&quot;).replace(&#x2F;&quot;&#x2F;g, &quot;&amp;quot;&quot;)}&quot;&gt;`).<p>• Do HTML sanitisation on <i>just the user input</i>, e.g. DOMPurify.sanitize(reply.content).<p>A part of my problem with the code as written is that, purely from looking at the code, I can see that there <i>may</i> well be various security holes. I require knowledge of the backend also before I can judge whether there <i>are</i> security holes. Where possible, it’s best to write the code in such a way that you <i>know</i> that it’s safe, or that it’s not—try not to depend on subtle things like “the <i>particular fields</i> that we access happen to be unable to contain angle brackets, ampersands and quotes”, because they’re fragile.<p>Incidentally, it would also be more efficient to run DOMPurify with the RETURN_DOM_FRAGMENT option, and append that, rather than concatenating it to a string and setting innerHTML. Saves a pointless serialisation&#x2F;deserialisation round trip, and avoids any possibility of new mXSS vulnerabilities that might be discovered in the future. (I don’t really understand why DOMPurify defaults to emitting a string. I can’t remember seeing a single non-demo use of DOMPurify where the string is preferable to a DOM fragment.)<p>—<p>† Though if the server sanitised arbitrary user-provided HTML&#x2F;MathML&#x2F;SVG, I probably don’t trust it as much as I trust DOMPurify, for things that end up in the DOM. There are some pretty crazy subtleties in things like HTML serialisation round-tripping of HTML, SVG and MathML content. There’s fun reading in the changelogs and security patches.
评论 #25576759 未加载
评论 #25575923 未加载
rajasimon超过 4 年前
I&#x27;m building a very simple solution for this. Checkout <a href="https:&#x2F;&#x2F;blogstreak.com" rel="nofollow">https:&#x2F;&#x2F;blogstreak.com</a> and I got recently featured on betalist.
评论 #25580926 未加载
zlynx超过 4 年前
Or your static page could have a link to a comments page. Which is also static.<p>It is pretty trivial to generate a new static page which includes the new comment. You do want some kind of database. A SQLite file works fine.
ggggtez超过 4 年前
&gt; manually escaping every field.<p>&gt; Some fields don&#x27;t look escaped.<p>hmm So the future of social media is everyone becoming software engineers huh. Good luck with those toots.