Grav Popular-Articles v1.0.1版本基础上做了优化
更灵活的路由过滤:
strpos($key, $blogRoute . '/') === 0
改为 strpos($route, $blogRoute) === 0
/blog
开头的路由,包括 /blog
本身和 /blog/*
增强调试功能:
配置处理优化:
空状态处理:
在文章页显示当前文章阅读量 :
{{ popular_articles.getViewsByRoute(page.route) }}
在文章中显示热门文章列表:
{# 热门文章列表 #}
{% if config.plugins['popular-articles'].enabled %}
{# 获取文章列表 #}
{% set articles_list = popular_articles.get() %}
<ul>
<li>热门文章</li>
{# 文章列表 #}
{% if articles_list|length > 0 %}
{% for item in articles_list %}
{% set article = item.page %}
<li>
<a href="{{ article.route }}"
{% if article.title|length > 30 %}title="{{ article.title }}"{% endif %}
style="display:flex; justify-content:space-between; align-items:center;">
{% if article.title|length > 30 %}
{{ article.title|slice(0, 27) ~ '...' }}
{% else %}
{{ article.title }}
{% endif %}
{{ item.views|default(0) }} 阅读
</a>
</li>
{% endfor %}
{% else %}
<li>暂无热门文章数据</li>
{% endif %}
</ul>
{% endif %}