AllinOne icon indicating copy to clipboard operation
AllinOne copied to clipboard

能集成第三方评论功能吗?

Open polar9527 opened this issue 5 years ago • 7 comments

比如 Gitment Disqus LiveRe

polar9527 avatar May 19 '19 04:05 polar9527

Disqus 是可行的喔,我的Blog就有加入Disqus評論了。

coreychen71 avatar May 25 '19 07:05 coreychen71

Hi, this is the maintainer of @staticmanlab, a public GitLab instance of Staicman. Here's some shortcomings of the commenting systems mentioned above.

  1. Gitment, Gitalk and Utterance support only GitHub, and they require user login before commenting. This can scare away many non programmers from leaving a comment to your posts. Besides, comments are part of the site's static content, not a software package problem. As a result, using GtiHub issues for comment storage is wrong in principle and bad in terms of SEO.
  2. Commento is not free as in free beer. For a personal blog with small traffic, you might find a monthly fee of $5 too expensive.
  3. Disqus and Isso contain a 3rd-party script to be loaded during page rendering. The code block for loading each of them shows that the static comments are not rendered as static HTML code. This hinders search engines from grabbing the comments, which are part of the site's content. As a result, that leads to suboptimal SEO.

You may avoid these problems by switching to Staticman, which makes use of GitHub/GitLab Pull/Merge Requests instead of issues. Under Staticman's model, static comments are YML/JSON files stored in the remote GitHub/GitLab repo (usually under data/comments, configurable through the path parameter in root-level staticman.yml), and through a static blog generator (Jekyll/Hugo/etc), the stored data are rendered as part of the content. This gives a total ownership of a static site's comments.

VincentTam avatar Jun 25 '19 21:06 VincentTam

@VincentTam Wow, that's great! Do you have any plan to add it to this theme?

zxdawn avatar Jun 26 '19 01:06 zxdawn

@zxdawn Not for now, but you may try porting from the diff between the Hugo theme Huginn: https://framagit.org/staticman-gitlab-pages/huginn/compare/e03609e8...4a9a46dc

Bascially, you just need to adjust the HTML form field names so that they match those of staticman.yml, and customize the CSS according to your theme.

VincentTam avatar Jun 26 '19 05:06 VincentTam

@VincentTam Thank you for your advice! I found this tutorial which you commented below. I tried to apply it to AllinOne:

  1. Add staticman.yml.

  2. Add these to the [params] part of config.toml:

  #Add staticman API URL to enable staticman comments
  staticman_api = "https://api.staticman.net/v2/entry/dancwilliams/networkhobo/master/comments"
  1. Add these after <!-- /.Prev & Next --> in layouts/_default/single.html:
        {{ if (.Params.comments) | or (and (or (not (isset .Params "comments")) (eq .Params.comments nil)) (.Site.Params.comments)) }}
          {{ if (.Site.Params.staticman_api) }}
            {{ partial "post-comments" . }}
          {{ end }}
        {{ end }}
  1. Add layouts/partials/post-comments.html, layouts/partials/comment-replies.html and layouts/partials/comment_form.html as same as that tutorial.

Then I got this error when rebuilding the site:

ERROR 2019/07/08 22:12:06 Error while rendering "page" in "blog/": template: _default/single.html:77:11: executing "main" at <partial "post-commen...>: error calling partial: template: partials/post-comments.html:7:33: executing "partials/post-comments.html" at <index $.Site.Data.co...>: error calling index: index of untyped nil
ERROR 2019/07/08 22:12:06 Error while rendering "page" in "sci-tech/": template: _default/single.html:77:11: executing "main" at <partial "post-commen...>: error calling partial: template: partials/post-comments.html:7:33: executing "partials/post-comments.html" at <index $.Site.Data.co...>: error calling index: index of untyped nil
Total in 27 ms
ERROR 2019/07/08 22:12:06 Failed to rebuild site: logged 2 error(s)

zxdawn avatar Jul 08 '19 14:07 zxdawn

@zxdawn Thanks for trying. Honestly speaking, I've no idea why such error occurs. From the error message, you may focus on layouts/partials/post-comments.html, which renders the static comments in data/comments. I know that that folder is non-existent in your repo, but that shouldn't cause an error. I'm not an expert in Hugo, so I can't tell you why. However, my template code in the link in my previous comment works, as you can see from the demo page for the theme: https://framagit.org/staticman-gitlab-pages/huginn.

:information_source: Note that Staticman v3 is already available. Since it's under active development, many users have reported in the app's GitHub issues. It's a distributed commenting system, meaning that everyone may run his/her own API instance, which might adopt some of the unmerged PR's. To get you started in minutes, I'm reusing my comment template.


:speech_balloon: This theme's comment support

:information_source: The following lines in your root-level site config file is responsible for comment support.

:frowning_woman: Inconvenience of comments stored in databases

:frowning: I'm not familiar with the actual procedures with FB comments. On my old GitHub pages + Octopress site, i used Disqus, but URL refactoring can lead to disappearance of comments. Changing the URL is complicated. Having LaTeX inside comments is impossible... Users don't own their comments.

:question: Why go static?

:globe_with_meridians: Static comments on my current Hugo + Staticman + KaTeX GitLab pages:
Staticman comment reply
Staticman comments with the theme Beautiful Hugo provided by halogenica/beautifulhugo#222

:bulb: What does "owning my comments" mean? You can do whatever you want with it.
Staticman + KaTeX + Beautiful Hugo

:1234: Static comments are treated like the site's static content, so you can use KaTeX for math display.

:heavy_check_mark: I ported others Staticman integration code to some Jekyll and Hugo templates.

:construction_worker_man: Staticman Configurations for GitHub/GitLab

:email: Please don't hesitate to ping me on GitHub/GitLab/leave a comment on my blog/send me an email to ask for help.

:muscle: Staticman's job is to get HTML form data to the GitHub/GitLab repo, and it won't care whether GitHub/GitLab Pages are used or not.

VincentTam avatar Jul 08 '19 16:07 VincentTam

:wrench: update

Plz set up your own Staticman instance ! For a guide, you may see https://github.com/pacollins/hugo-future-imperfect-slim/wiki/staticman.yml, which is inspired from https://hajekj.net/2020/04/15/staticman-setup-in-app-service/.

VincentTam avatar Feb 11 '21 15:02 VincentTam