Commento loads different comments if there's a trailing slash in URL
I just discovered that Commento seems to register URLs with or without trailing slashes as different posts. Is this expected behavior? Is there any way to redirect the version with the trailing slash to the version without, so comments won't keep being split on future posts?
Once again answering my own question here, but just in case this is of interest to anyone else: You can add a data attribute to the Commento <script>
tag that assigns an id to the page it's embedded on, so the comments aren't loaded based on the url but based on that id. In my entry.html I replaced this:
{{> plugin_html}}
With this:
<script defer
src="https://cdn.commento.io/js/commento.js"
data-page-id="{{slug}}">
</script>
<div id="commento"></div>
And since {{slug}} always seems to give you the version without trailing slash, you get the same comments loading no matter which version you visited.
So basically my only question left is, since I don't know exactly what {{> plugin_html}} does apart from inserting the basic Commento script: Am I breaking anything else by doing it this way?
Answered 3 years ago · Edit answerYou're not breaking anything and that seems like a good solution! I'll merge in these changes so everyone else can benefit, thanks for uncovering this
Answered 3 years ago · Edit answerThanks for the reply, good to know that this will work! Another small suggestion though if you wanna make this change for everyone: I noticed that, while this solution worked for new comments, none of the comments posted before the change were showing anymore (neither from the version with nor the one without trailing slash). Fix for that is using "/{{slug}}" instead, then it's in line with how Commento handles these ids by default and you get to keep at least the comments from one version.
Answered 2 years ago · Edit answer