francodacosta / grav-plugin-page-stats

better page stats for Grav
MIT License
7 stars 4 forks source link

Stats links broken when Grav is not in the web root #34

Open bleutzinn opened 1 year ago

bleutzinn commented 1 year ago

First of all thanks for this great plugin!

On development and often in production too I have Grav installed in a subdirectory.

If so the ''view page' and 'view page stats' links on the 'admin/page-stats' page do not have the subdirectory or path in them. They always link to the web root.

For example if I have Grav in 'htdocs/grav' on localhost the URL of the standard 'typography' page is http://localhost/grav/typography. However the 'view page' link is http://localhost/typography and the 'view page stats' link is http://localhost/admin/page-stats/page-details?page=/typography.

francodacosta commented 1 year ago

@bleutzinn can you change false to true on https://github.com/francodacosta/grav-plugin-page-stats/blob/master/page-stats.php#L209 and let me know if it works ?

Otherwise I have to look at it with more attention

bleutzinn commented 1 year ago

It does fix the problem with links to pages but unfortunately all links to stats remain broken. That is all links with the fa-line-chart icon. For example the URL of the Top Users statistics details is http://localhost/grav/admin/page-stats/top-users but the link is http://localhost/admin/page-stats/top-users.

bleutzinn commented 1 year ago

It appears that adding the theme variable home_url to the start of links adds the subdirectory in which Grav is installed.

For example in https://github.com/francodacosta/grav-plugin-page-stats/blob/master/themes/admin/templates/widgets/recently-viewed-pages.html.twig#L54 changing href="{{ pageStats.urls.pageDetails}} to href="{{ home_url }}{{ pageStats.urls.pageDetails}}.

The documentation) states that the home_url variable takes the currently active language into account. So I tested using an active language and it works okay. I did not test with Grav being in the document root.