theme: fix showVisitedLinks in case Hugo is configured to modify relative URLs #86

This commit is contained in:
Sören Weber 2021-09-09 21:03:37 +02:00
parent 5ef91dbbce
commit c5382e0bcc
No known key found for this signature in database
GPG key ID: 07D17FF580AE7589
2 changed files with 7 additions and 2 deletions

View file

@ -135,7 +135,7 @@
</li>
{{else}}
<li data-nav-id="{{.RelPermalink}}" title="{{.Title}}" class="dd-item{{if eq .File.UniqueID $currentFileUniqueID}} active{{end}}">
<a href="{{ .RelPermalink}}">
<a href="{{.RelPermalink}}">
{{ partial "menu-pre.html" . }}{{or .Params.menuTitle .LinkTitle .Title}}{{ partial "menu-post.html" . }}
{{ if $showvisitedlinks}}<i class="fas fa-check read-icon"></i>{{end}}
</a>

View file

@ -527,7 +527,12 @@ jQuery(function() {
// loop through the sessionStorage and see if something should be marked as visited
for (var url in sessionStorage) {
if (sessionStorage.getItem(url) == 1) jQuery('[data-nav-id="' + url + '"]').addClass('visited');
if (sessionStorage.getItem(url) == 1){
// in case we have `relativeURLs=true` we have to strip the
// relative path to root
url = url.replace( /\.\.\//g, '/' ).replace( /^\/+\//, '/' );
jQuery('[data-nav-id="' + url + '"]').addClass('visited');
}
}
});