New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making it easy to add comments #1222

Closed
dplanella opened this Issue Apr 10, 2017 · 5 comments

Comments

Projects
None yet
2 participants
@dplanella

dplanella commented Apr 10, 2017

It is relatively easy to add Disqus comments to a Gollum wiki by using their universal embed code.

That works fine for the most basic case, but it messes up the commenting system when pages are renamed in Gollum, as there is no way to track a page by a unique identifier. That is, at the time of writing there is no way to specify a meaningful value for these variables in the Disqus JS embed code snippet:

this.page.url = PAGE_URL;  // Replace PAGE_URL with your page's canonical URL variable
this.page.identifier = PAGE_IDENTIFIER; // Replace PAGE_IDENTIFIER with your page's unique id

The way I added Disqus comments was to simply add a mustache partial template ({{>comments}}) that contains the Disqus embed code, and then modified the stock page.template to reference it. Finally, I copied all stock templates plus the new comments.mustache and modified page.mustache ones to a location of my choice and pointed Gollum to it via the template-dir option (see also issue #1221).

Using that method, and unless I'm mistaken, limits me to use only the Ruby variables defined in page.rb in the page.mustache and included partial templates.

Would it be possible to expose a unique page ID and the page URL there? Happy to be pointed to an alternative way to access them, too.

Thanks!

@dometto

This comment has been minimized.

Member

dometto commented Apr 10, 2017

There is not really such a thing as a unique identifier of a file in git. Doing git mv basically amounts to deleting the file at the old path, and recreating a file with the same contents at a different path. The closest thing is the page's SHA1 hash -- but of course it's possible to have different pages with the same content and so the same hash in your repo. I would be happy to expose a method returning the page's SHA1 hash though, if that works for your.

Alternatively, perhaps you could fabricate unique ids yourself, and store them in the page as metadata tags. Use the following syntax:
<!-- --- unique_id: 31415 -->
Metadata is available in the Page view, so you should be able to reference it in the template.

Note that starting from version 5.0, gollum will use YAML front matter instead of these old-style metadata tags.

@dplanella

This comment has been minimized.

dplanella commented Apr 10, 2017

Thanks a lot for the reply. I had actually thought about the metadata too, but I discarded it as it would be a pain to maintain a manual index for each page. I noticed the upcoming change of metadada format, thanks for the tip and for the release notes. Looking forward to 5.0!

I think exposing the SHA1 hash would be quite useful for this purpose. I understand that it's not unique as you are saying, but I think you'd generally not have two pages with the exact same content on a wiki.

@dometto dometto added the improvement label Apr 12, 2017

@dometto

This comment has been minimized.

Member

dometto commented Apr 12, 2017

Implemented in #1223, which will be in v5.0

@dometto dometto closed this Apr 12, 2017

@dplanella

This comment has been minimized.

dplanella commented Apr 16, 2017

Excellent, thanks!

@dplanella

This comment has been minimized.

dplanella commented Oct 10, 2017

Just making a note here so that when v5.0 is released I don't need to look it all up again :)

Essentially, we'll be then able to use these variables in the Disqus embed code:

  this.page.url = '{{{page.url_path}}}';
  this.page.identifier = '{{{page.sha}}}';
  • page.url_path: note that this is already available at this time. However, it's not perfect for this use case, as it outputs the relative path. As far as I could tell, there was no variable available that outputs the absolute path.
  • page.sha: will only be available once Gollum v5.0 is released. It outputs a unique identifier based on the SHA commit id of the page. See caveats on the previous comments re: true uniqueness.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment