Static comment for hugo


#1

Hello,

Does Hugo support the static comment? I’ve looked at this link https://gohugo.io/extras/comments/ but I didn’t see any information about supporting the static comment.

I prefer not to use Disqus or anything that are not static.

If Hugo doesn’t support the static comment at this stage then I like to propose the following features. (Note: According to this page http://discuss.gohugo.io/t/whats-the-plan-for-plugins/350 and this http://discuss.gohugo.io/t/using-for-plugins-in-hugo/1239/2, creating the plugin for Hugo is not supported so we can’t create our own plugin for that too. )

Hugo Comment Command

A simple command that allows us to create a comment under a post.

For example: hugo new comment/first.md

Or, maybe we can use the existing hugo new command to create a new markdown file under ‘comment’

Why?

It will allows us to do the following things ~

Comment Api for Theme

list.html

  • ‘.Comments.Count’

single.html

{{ range .Comments }} .Author .Website .Email .Content {{end}}

Of course, when we build, the comments should be generated to the public folder as well.

If this feature is already supported then please share me the link so I can go and read it. I am still new to hugo and I started a few days back.

Thanks!


#2

Edit: I found this discussion https://github.com/spf13/hugo/issues/160 and the conclusion was to go with kaiju ( https://github.com/spf13/kaiju ).

Kaiju looks great but it doesn’t let us to create the static comments.

  • Comment Migration: We can import the existing comment to Disqus or etc. but we need to have the JS code that load the comments from 3rd-party service. It’s the cost to the performance. Plus, it allows 3rd-party provider to load what they want to load along with our comment feeds. For example: Disqus load the related comments by default. Would it be better if we can import the comment to Hugo and generates the static file?

  • Search (read only) : I don’t search the comment much but if we need to support it, any search engine that can search the static HTML should be able to search the static comment as well.

  • Commenting (public write) : We can let the blog owner to decide whether they want to do a simple ‘email to comments’ (https://caurea.org/2012/03/31/this-blog-has-comments-again.html) or just have a simple custom form that loads nothing but allow the commenter to send the comment to the server. And the blog owner or CI or that server will create a comment (maybe using hugo new comment/title.md ) and rebuild the blog to generate the new comment.

  • Edit (private write) : We can use the same approach as “Commenting” but I don’t mind sacrificing this feature.

  • Real time comment capabilities : Nice to have but I can live without this feature.

  • Push the latest comment : Nice to have

  • Pagination for comments: I think this is a must-have feature.

  • Nested Comment (post/reply) : Nice to have. Even facebook supports only 1 deep-level.

According to this post http://discuss.gohugo.io/t/using-for-plugins-in-hugo/1239, @spf13 said that Hugo 0.13 was rewritten to add internal support for handlers based on filetype.

Is it possible for us to create a plug in that can generate the comments and expose some Api for themes to use?


#3

On Mon, 26 Oct 2015 07:27:39 +0000 michaelsync discuss@gohugo.io wrote:

Kaiju looks great but it doesn’t let us to create the static
comments.

If you want your own open-source comments, I can recommend Isso
(https://github.com/posativ/isso)…however, it’s Python. :wink:


#4

Thanks @gour

What would be the build flow if I use that tool? I mean, Will this tool generates/import the comments as markdown files under hugo content folder? How will hugo pick up those files when I build to generate the static site to public folder? What do we need to change in theme? I assume that is no API for comments in creating a theme.


#5

On Mon, 26 Oct 2015 10:37:00 +0000 michaelsync discuss@gohugo.io wrote:

What would be the build flow if I use that tool? I mean, Will this
tool generates/import the comments as markdown files under hugo
content folder? How will hugo pick up those files when I build to
generate the static site to public folder? What do we need to change
in theme? I assume that is no API for comments in creating a theme.

Well, Isso is similar to Disqus in a sense that it’s server-side
technology, so you have to install it on your production server.
Recommended setup is with e.g. uWSGI and it uses sqlite3 as database
back-end.

You can take a look at Nikola (python static-site generator) which has
support for Isso, but it simply involves to add Javascript snippet to
every Hugo-generated page, possibly by adding it to your preferred theme
similar to methods involved to add support for Disqus, analytics etc.

There is some work involved for the price of not depending on 3rd party
service ala Disqus. :wink:


#6

@gour I see! Thanks!

It’s good idea if I want to host my own service. :slight_smile:

But I would prefer having the generated static comments instead of loading the comment feeds from 3rd-party service or my own service. I think that having the static comment might be faster compared to loading the feed using javascript.


#7

I would have said that type of ‘static comment’ is doable now. It could just be stored as content and displayed much like blog posts. All you’d need is each comment created as a separate .md file.

FYI, the beginning sentence of this thread wasn’t clear to me with regard to what is wanted.

a static site generator cannot support this as a whole feature when is self-hosted, as getting the comments is a server side task.


#8

I think Kaiju is dead. The repo hasn’t been updated in years and I’ve asked twice about it on here and not got a single reply [even from its developer!].


#9

Thanks!

How do I show the comment in single.html?

Let’s say I did the following things.

  1. hugo new post/first.md (I created a dummy post )
  2. hugo new comment/first.md (I created a comment or list of comment for my dummy post “first.md”. Is it a good idea? )
  3. hugo new theme my-theme ( I created a theme )

In index.html of my-theme, I have the code below so it shows the list of posts. I haven’t considered about the pagination yet. How do I get the count of comments here? maybe read “comment/first.md”?

<html>
{{ partial "header.html" . }}
<body>
{{ range  where .Data.Pages "Section" "post" }}
	  <a href="{{ .Permalink }}">
		{{ .Title }}
	  </a>	
 {{ .Content }}
{{ end }}
</body>
</html>

In _default/single.html, I have the code below. How do I show “comment\first.md” in “post\first.md” here?

    <h1>{{ .Title }}</h1>
	{{ .Content }}

I guess I need to do something with archetypes or content-type or sections maybe post content section + comment section


#10

I know the answer now. I can get the list of comments with this code below. But …

Single.html

<h1>{{.Section}}</h1>
<h2>{{.Title}}</h2>
<p>{{.Content}} </p>

{{ range  where $.Site.Pages "Section" "comment" }}
	  <a href="{{ .Permalink }}">
		{{ .Title }}
	  </a>	
 {{ .Content }}
{{ end }}

There are still a few issues. I will post about them later.


#11

I think I managed to get what I want to achieve now. I will share it for feedback after I’ve done a few tests.

Thanks all!


#12

Dead is a strong word… but yeah, it’s in a coma. I only have so much time and without help from a community I think Kaiju will remain where it is. It’s sad, it’s a good program, but needs some love.


#13

@spf13

I think it would be even better if hugo supports the static comments instead of loading the list of comments dynamically from 3rd party. Of course, the static site won’t allow users to post the comment but we can deal with it later.

As of now, I managed to use archetype + type + section to make the static comment work for my test site. It would be better if hugo support out of box (except public-write). I am modifying the “wordpress to hugo exporter” to generate the static comments now. I will share my change and love to get some feedback on it.


#14

Maybe it’s just pining for the fjords!


#15

Hi Michaelsync, have you followed up your approach? I think straight about exactly the same solution. Static comments are the simplest way to publich comments.


#16

This is an old post, but I’d like to bring it to the foreground again (if I missed a newer follow-up, please let me know).

The benefit of static comments is long term: when the site is no longer active, it can still be used and archived in full, even at archive.org, really long-term.

Given Hugo’s speed, wouldn’t it be possible to simply regenerate the entire site after a new comment has been posted? As web-hook, basically?

This approach seems so obvious to me that I keep wondering why it hasn’t been pursued (or perhaps more likely: why I haven’t found it).

-jcw


Hugo as static FORUM generator?