schn4ck / schnack

🗣️ Simple self-hosted node app for Disqus-like drop-in commenting on static websites
https://schnack.cool/
Other
1.82k stars 84 forks source link

Slack %SLUG% #78

Open ghost opened 6 years ago

ghost commented 6 years ago

slack.js: const post_url = config.get('page_url').replace('%SLUG%', event.slug)+'#comment-'+event.id;

page_url: "page_url": "https://example.com/%SLUG%",

In blogpost:

<h1 id="try-schnack">
<a class="anchor" href="#try-schnack">
 Try schnack</a>
 </h1>
<div class="comments-go-here"></div>
<% var title = post.title %>
<% var slug = post.slug %>
<% var sluglink = [title,slug].join('+++++') %>
<script type="text/javascript"
    src="https://schnack.example.com/embed.js" 
    data-schnack-slug="<%= sluglink %>"
    data-schnack-target=".comments-go-here">
</script>

This all works. But I need output following: title/slug and NOT title+++++slug

If I do .join('/') then schnack does not work at all, it fully crashes. I need the slash / as separator between title and slug.

How to fix?

gka commented 5 years ago

So the idea behind the slug was that you use the part of your blog post urls that is different for every post.

let's say your blog urls look like this:

https://mysite.com/blog/2018-11/this-is-a-post.html https://mysite.com/blog/2018-10/another-post-right-here.html https://mysite.com/blog/2017-04/a-really-old-post.html

then the url schema can be described as:

https://mysite.com/blog/ + slug + .html

and the slugs would be 2018-11/this-is-a-post, 2018-10/another-post-right-here and 2017-04/a-really-old-post.

in this scenario you'd set the page_url schnack config to be

{
   "page_url": "https://mysite.com/blog/%SLUG%.html"
}

and it should all work with slack.

gka commented 5 years ago

closing this for now

kon-foo commented 5 years ago

There is more to this. The "/" in the slug causes a problem. See:

https://schnick.schnack.cool/comments/post-slug -> returns 200
https://schnick.schnack.cool/comments/post/slug -> returns 404

To solve this I had to escape the "/" in the form of "post%2Fslug" and configure my webserver to allow escaped slashes so that:

https://schnick.schnack.cool/comments/post%2Fslug returns 200