Skip to content

Commit

Permalink
fix: Valine visitor count not working when set site_prefix to compl…
Browse files Browse the repository at this point in the history
…ete url
  • Loading branch information
AlanDecode committed Jan 8, 2020
1 parent dca7fe8 commit 879cc3f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion __init__.py
Expand Up @@ -8,7 +8,7 @@
from Maverick.Content import ContentList, group_by_category, group_by_tagname
from Maverick.Utils import logged_func, gen_hash, unify_joinpath, copytree
from Maverick.Utils import safe_write, safe_read
from .utils import tr, build_navs, build_links
from .utils import tr, build_navs, build_links, filterPrefix

import os
import re
Expand All @@ -28,6 +28,7 @@ def render(self):
self._env.globals['len'] = len
self._env.globals['build_navs'] = build_navs
self._env.globals['build_links'] = build_links
self._env.globals['get_path'] = filterPrefix

try:
from Maverick.Markdown import g_hooks
Expand Down
2 changes: 1 addition & 1 deletion templates/includes/skeleton_content.html
Expand Up @@ -38,7 +38,7 @@ <h1 class="ga-post_title">{{ content.get_meta('title') }}</h1>
{% endif %}
{% if config.valine['enable'] and config.valine.get('visitor', False) and content.get_meta('comment') %}
<span class="leancloud_visitors"
id="{{ Router.gen_permalink_by_content(content) }}"
id="{{ get_path(Router.gen_permalink_by_content(content)) }}"
data-flag-title="{{ content.meta['title'] }}"> · <i class="leancloud-visitors-count"></i> Views</span>
{% endif %}
</span>
Expand Down
6 changes: 6 additions & 0 deletions utils.py
Expand Up @@ -38,3 +38,9 @@ def build_navs(navs):
list.append(
'<li><a href="#" target="_self" class="search-form-input ga-highlight">%s</a></li>' % tr('Search'))
return '<ul>%s</ul>' % ('<span class="separator">·</span>'.join(list))


def filterPrefix(url: str):
"""replace prefix with `/`, to fix Valine view counting
"""
return url.replace(g_conf.site_prefix, "/")

0 comments on commit 879cc3f

Please sign in to comment.