Addpixel / KirbyComments

[Kirby 2] File-based comments stored as subpages for the Kirby CMS.
MIT License
68 stars 4 forks source link

Prevent the URL from adding the hash with the comment-number #26

Closed liaprins closed 7 years ago

liaprins commented 7 years ago

Hi there, I am loving this Kirby plugin, but there is one thing I haven't been able to figure out how to modify:

After I post a comment, the URL gets a #hash appended to it with the comment number following, e.g. "#comment-11"

Example screenshot:

screen shot 2017-08-15 at 8 00 46 pm

This is problematic because refreshing the page (e.g. command + R) does not remove the #hash from the URL, so if I user posts a comment and then wants to copy and paste the URL to share elsewhere, it will have the #hash, and the shared link will anchor to the bottom of the screen where the comment is, rather than to the article as a whole. (My use case for comments is very simple and does not require the need to reference them with their own individual links; a clean link to the article as a whole is more of a priority).

Another problem with this is it is messing with clicking the browser "back" button: the back button now keeps you on the same page, it just removes the #hash from the URL, and you have to hit the back button a second time to go to the actual previous page.

If you could just direct me to how this could be changed, and in which files, that would be great! Thank you so much!

florianpircher commented 7 years ago

Setting a hash is done in the standard snippet (snippets/comments-form.php). You can copy its contents and create your own snippet (e.g. site/snippets/my-comments-form.php) and remove the hash from the <form>s action:

Before:

<form action="#comment-<?= $comments->nextCommentId() ?>" ...

After:

<form action="." ...

Instead of including the standard snippet, you then have to include your own snippet:

<?php snippet('comments-list') ?>
<?php snippet('my-comments-form') ?>
liaprins commented 7 years ago

Thanks!