# Plugin Website Comments/Ratings Implementation

**URL:** <https://discourse.joplinapp.org/t/plugin-website-comments-ratings-implementation/26825>\
**Category:** Plugin Website\
**Tags:** gsoc-2022\
**Created:** [10 August 2022 08:25 UTC](https://discourse.joplinapp.org/t/plugin-website-comments-ratings-implementation/26825 "2022-08-10T08:25:19Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Retr0ve](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/retr0ve/32/12960_2.png) [@Retr0ve](https://discourse.joplinapp.org/u/Retr0ve)\
**Post date:** [10 August 2022 08:25 UTC](https://discourse.joplinapp.org/t/plugin-website-comments-ratings-implementation/26825/1 "2022-08-10T08:25:19Z")

</div>

## Overview

Usually a plugin site or an extension store has features allowing users to comment and rate a specific item. This kind of interactive feature requires a backend to provide data dynamically. Normally, for dynamic sites, they can use their own API and backend to do that. But for static websites like Plugin Website for Joplin, we have to borrow the power from an existing API provider such as Github API or Discourse API.

The general idea is that, when a user visits the website, the website will send an asynchronize request to the API to pull data dynamically. And when a user writes a comment or submits a rating to a plugin, the website will create a request to the API to update the data.

**UPDATE:**  
After further investigating how other static websites(like blogs, product promotion sites, etc)([example](https://blog.codinghorror.com/welcome-to-the-internet-of-compromised-things/#discourse-comments)) did, I found that most of them only display the comments. And you have to go to places like GitHub issues or the forum to post a new comment.

I think this makes sense since it's dangerous to let users put content directly from front-end without an authorization system. And for these two APIs, you have to have a API KEY to post thing to it which can be dangerous if we coded it into the front-end without proper permission control, too.

So maybe embed the Discourse Comment Embeds into the website is the better way for us now.

> **Original Content**
>
> ## Choice of API
> 
> Potentially, I have two options in my mind. The first one is the Github API. Github API has the power to perform CRUD operations on repos, issues, gists and etc. For example, we can store the comments and rating data inside a gist, and using Github API to retrieve and update these data.
> 
> To get a gist simply send a GET request to `/gists/{gist_id}` endpoint. It will return the file in `files` field. And to update a gist, send a PATCH request to `/gists/{gist_id}` with a body contains the file.
> 
> The downside of using Github API is that
> 
> 1. It has limitations on requests per hour. For anonymous users, it is 60 times per hour. And for authorized users, it is 5000 times per hour.
> 2. It might be unstable for users in specific regions, like China.
> 
> The second one is Discourse API. The idea is basically the same as the Github API, the difference is we are creating a post in this forum to keep track all the data.
> 
> We can retrieve post from `https://{defaultHost}/posts/{id}.json` and update post by sending a PUT to `https://{defaultHost}/posts/{id}.json`.
> 
> There are also downsides to this one:
> 
> 1. API key required, it is generated from the admin pane. I don't know if there is permission control on this, if not then it might be dangerous to use this API on the front end.

Let me know if you know better ways to implement interactive components on a static website. Any discussion is appreciated!

---

<div class="post-metadata">

**Author:** ![PackElend](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/packelend/32/488_2.png) [@PackElend](https://discourse.joplinapp.org/u/PackElend)\
**Post date:** [10 August 2022 10:46 UTC](https://discourse.joplinapp.org/t/plugin-website-comments-ratings-implementation/26825/2 "2022-08-10T10:46:03Z")

</div>

> [@Retr0ve](#):
>
> The first one is the Github API.

that may simplify it: [https://utteranc.es/](https://utteranc.es/)

> [@Retr0ve](#):
>
> The second one is Discourse API. The idea is basically the same as the Github API, the difference is we are creating a post in this forum to keep track all the data.

I guess this is preferred as it would keep all information within the forum. Is there an action you can reference the related GH Issue / PR

---

<div class="post-metadata">

**Author:** ![Retr0ve](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/retr0ve/32/12960_2.png) [@Retr0ve](https://discourse.joplinapp.org/u/Retr0ve)\
**Post date:** [10 August 2022 11:04 UTC](https://discourse.joplinapp.org/t/plugin-website-comments-ratings-implementation/26825/3 "2022-08-10T11:04:49Z")

</div>

> [@PackElend](#):
>
> that may simplify it: [https://utteranc.es/](https://utteranc.es/)

That makes it easier!

> [@PackElend](#):
>
> I guess this is preferred as it would keep all information within the forum. Is there an action you can reference the related GH Issue / PR

I don't know if there is anyone has done this before. But I think the main problem is that if you want to use this API, you need an API key generated by admin which might causes permission leaks.

---

<div class="post-metadata">

**Author:** ![PackElend](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/packelend/32/488_2.png) [@PackElend](https://discourse.joplinapp.org/u/PackElend)\
**Post date:** [10 August 2022 11:25 UTC](https://discourse.joplinapp.org/t/plugin-website-comments-ratings-implementation/26825/4 "2022-08-10T11:25:40Z")

</div>

> [@Retr0ve](#):
>
> I don't know if there is anyone has done this before

It looks like you wouldn't the first one

> <https://github.com/mypaint/mypaint.github.io/issues/17>
>
> It would probably be nice to embed Discourse as our Comment system for our blog.… The biggest plus side would that we wouldn't have to manually create a new comment thread on our discourse site like we are doing now. The other plus side, is that since Jekyll uses templates and layouts to generate the static site, all we need to do is add Javascript layout a \`comments.html\` in the \`\_includes\` folder and add it to the \`post.html\` in the \`\_layouts\` folder. That way Jekyll with automatically add the js snippet on each new post. Lastly it will further strengthen us encouraging to using our forums which would be nice. 
> 
> The downside however, is that well have to use Javascript. I would like to use a little js as possible, to avoid site overhead, but the pros do out weight the cons in this situation. So what are your guys thoughts? Should we implement this? Are there alternative ways to implement this with out using Javascript.
> 
> \[Example thread of how it would look\](http://eviltrout.com/2014/01/04/hiding-offscreen-ember.html)
> \[How to Embed it\](https://meta.discourse.org/t/embedding-discourse-comments-via-javascript/31963)
> \[Example of how one implemented it on Github Pages\](https://meta.discourse.org/t/trouble-embedding-discourse-as-a-comment-engine-using-github-pages-and-digitalocean/17520)

> <https://github.com/oslc-op/website/issues/15>
>
> Once we have the blog up and running, let's try a basic proof of concept for usi…ng Discourse as our post commenting system. Some themes use this out of the box, so we can possibly use one of them as a reference.
> 
> e.g.
> https://themes.gohugo.io/hugo-uno/
> 
> There is also some relevant articles around to help, including:
> 
> https://gohugo.io/extras/comments/
> https://meta.discourse.org/t/embedding-discourse-comments-via-javascript/31963
> 
> A prerequisite for this is to have our Discourse up and running, which is being tracked in issue https://github.com/OSLC/oslc-community/issues/1

---

<div class="post-metadata">

**Author:** ![Retr0ve](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/retr0ve/32/12960_2.png) [@Retr0ve](https://discourse.joplinapp.org/u/Retr0ve)\
**Post date:** [10 August 2022 13:42 UTC](https://discourse.joplinapp.org/t/plugin-website-comments-ratings-implementation/26825/5 "2022-08-10T13:42:37Z")

</div>

It seems that Discourse Embed is the way to go. But it requires users to navigate to the forum to post comments, is that acceptable?

> **[Embedding Discourse Comments via Javascript](https://meta.discourse.org/t/embedding-discourse-comments-via-javascript/31963)**
>
> Discourse has the ability to embed the comments from a topic in a remote site using a Javascript API that creates an IFRAME. For an example of this in action, check out Coding Horror’s blog. The blog is run via Ghost but the comments are embedded...

---

<div class="post-metadata">

**Author:** ![PackElend](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/packelend/32/488_2.png) [@PackElend](https://discourse.joplinapp.org/u/PackElend)\
**Post date:** [11 August 2022 12:06 UTC](https://discourse.joplinapp.org/t/plugin-website-comments-ratings-implementation/26825/6 "2022-08-11T12:06:26Z")

</div>

I guess so, read some conversation and it seems that direct answer won't come

---

<div class="post-metadata">

**Author:** ![Retr0ve](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/retr0ve/32/12960_2.png) [@Retr0ve](https://discourse.joplinapp.org/u/Retr0ve)\
**Post date:** [14 August 2022 08:29 UTC](https://discourse.joplinapp.org/t/plugin-website-comments-ratings-implementation/26825/7 "2022-08-14T08:29:51Z")

</div>

Hi PackElend,  
Can you set up Discourse as [Embedding Discourse Comments via Javascript - developers - Discourse Meta](https://meta.discourse.org/t/embedding-discourse-comments-via-javascript/31963) so I can embed it into the Plugin Website? We can have all the comments posts under the plugin category or we can have a new category for this.

---

<div class="post-metadata">

**Author:** ![laurent](https://avatars.discourse-cdn.com/v4/letter/l/ce7236/32.png) [@laurent](https://discourse.joplinapp.org/u/laurent)\
**Post date:** [14 August 2022 08:49 UTC](https://discourse.joplinapp.org/t/plugin-website-comments-ratings-implementation/26825/8 "2022-08-14T08:49:32Z")

</div>

With these two approaches how do you deal with race conditions (multiple users commenting or voting at the same time)?

---

<div class="post-metadata">

**Author:** ![Retr0ve](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/retr0ve/32/12960_2.png) [@Retr0ve](https://discourse.joplinapp.org/u/Retr0ve)\
**Post date:** [14 August 2022 09:37 UTC](https://discourse.joplinapp.org/t/plugin-website-comments-ratings-implementation/26825/9 "2022-08-14T09:37:12Z")

</div>

After further investigating how other static websites(like blogs, product promotion sites, etc) did, I found that most of them only display the comments. And you have to go to places like GitHub issues or the forum to post a new comment.

I think this makes sense since it's dangerous to let users put content directly from front-end without an authorization system. And for these two APIs, you have to have a API KEY to post thing to it which can be dangerous if we coded it into the front-end without proper permission control, too.

Building an authorization system is barely impossible for a static website (at least for me). So I believe embed the Discourse into the website is the better way for us now.

---

<div class="post-metadata">

**Author:** ![laurent](https://avatars.discourse-cdn.com/v4/letter/l/ce7236/32.png) [@laurent](https://discourse.joplinapp.org/u/laurent)\
**Post date:** [14 August 2022 09:59 UTC](https://discourse.joplinapp.org/t/plugin-website-comments-ratings-implementation/26825/10 "2022-08-14T09:59:07Z")

</div>

How do you handle a case like this?

- User 1 download the post
- User 2 download the post
- User 1 adds a comment
- User 2 adds a comment

In that case the changes from user 1 will overwritten by the changes from user 2, and one of the comment will be lost. I don't think any of your solutions handle this at the moment.

Also most of this logic is client side - how do we handle someone purposely deleting the complete content or replacing it with broken content?

---

<div class="post-metadata">

**Author:** ![Retr0ve](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/retr0ve/32/12960_2.png) [@Retr0ve](https://discourse.joplinapp.org/u/Retr0ve)\
**Post date:** [14 August 2022 10:23 UTC](https://discourse.joplinapp.org/t/plugin-website-comments-ratings-implementation/26825/11 "2022-08-14T10:23:47Z")

</div>

Thanks for explaining what race condition is, but my point is we don't have to deal with these issues ourselves because Discourse and Github handles them. As I said earlier, we might need to let users to go to places like Github Issues or this forum to post new comments. And in that way we only display comments in the Plugin Website and not allowing them to post comments directly under Plugin Website.

BTW, excuse me for my bad grammar, please let me know if you have trouble understanding my wording.

> [@laurent](#):
>
> Also most of this logic is client side - how do we handle someone purposely deleting the complete content or replacing it with broken content?

That's why I'm suggesting to embed Discourse in the site.

> [@Retr0ve](#):
>
> it's dangerous to let users put content directly from front-end without an authorization system. And for these two APIs, you have to have a API KEY to post thing to it which can be dangerous if we coded it into the front-end without proper permission control, too.
> 
> Building an authorization system is barely impossible for a static website (at least for me). So I believe embed the Discourse into the website is the better way for us now.

---

<div class="post-metadata">

**Author:** ![PackElend](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/packelend/32/488_2.png) [@PackElend](https://discourse.joplinapp.org/u/PackElend)\
**Post date:** [14 August 2022 12:15 UTC](https://discourse.joplinapp.org/t/plugin-website-comments-ratings-implementation/26825/12 "2022-08-14T12:15:11Z")

</div>

@Retr0ve you may share some references where it is implemented, that probably makes all easier

---

<div class="post-metadata">

**Author:** ![Retr0ve](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/retr0ve/32/12960_2.png) [@Retr0ve](https://discourse.joplinapp.org/u/Retr0ve)\
**Post date:** [14 August 2022 15:45 UTC](https://discourse.joplinapp.org/t/plugin-website-comments-ratings-implementation/26825/13 "2022-08-14T15:45:05Z")

</div>

Sure! Here is an example(a blog) that uses Discourse Comment Embed.

> **[Welcome to The Internet of Compromised Things](https://blog.codinghorror.com/welcome-to-the-internet-of-compromised-things/#discourse-comments)**
>
> This post is a bit of a public service announcement, so I'll get right to the point: Every time you use WiFi, ask yourself: could I be connecting to the Internet through a compromised router with malware? It's becoming more and more common to see...

---

<div class="post-metadata">

**Author:** ![laurent](https://avatars.discourse-cdn.com/v4/letter/l/ce7236/32.png) [@laurent](https://discourse.joplinapp.org/u/laurent)\
**Post date:** [14 August 2022 16:05 UTC](https://discourse.joplinapp.org/t/plugin-website-comments-ratings-implementation/26825/14 "2022-08-14T16:05:14Z")

</div>

What you say now is in contradiction with what you said in your initial post. So did you make a mistake or were you completely unclear?

---

<div class="post-metadata">

**Author:** ![Retr0ve](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/retr0ve/32/12960_2.png) [@Retr0ve](https://discourse.joplinapp.org/u/Retr0ve)\
**Post date:** [15 August 2022 01:22 UTC](https://discourse.joplinapp.org/t/plugin-website-comments-ratings-implementation/26825/15 "2022-08-15T01:22:57Z")

</div>

It is something we discover while investigating how others did this. You can say it's a mistake.

---

<div class="post-metadata">

**Author:** ![PackElend](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/packelend/32/488_2.png) [@PackElend](https://discourse.joplinapp.org/u/PackElend)\
**Post date:** [15 August 2022 11:59 UTC](https://discourse.joplinapp.org/t/plugin-website-comments-ratings-implementation/26825/16 "2022-08-15T11:59:36Z")

</div>

> [@Retr0ve](#):
>
> You can say it's a mistake.

may you want to update the OP to avoid anyone has to read through all posts to get the clue out of it
