This commit is contained in:
amehime
2020-09-25 00:42:06 +08:00
parent b28ca8f9ee
commit 3b724c254b
2 changed files with 25 additions and 22 deletions

23
layout/_macro/widget.njk Normal file
View File

@@ -0,0 +1,23 @@
{% macro render() %}
<div class="widgets">
<div class="rpost pjax">
<h2>{{__('index.random_posts')}}</h2>
<ul>
{%- set posts = site.posts.shuffle().limit(10).toArray() %}
{%- for item in posts %}
{%- if item.link %}
{%- set postTitleIcon = '<i class="ic i-link-alt"></i>' %}
{%- endif %}
<li class="item">
{{ breadcrumb.render(item, false) }}
{%- set postText = item.title or item.link or __('post.untitled') %}
<span>{{ _url(item.link or item.path, postText + (postTitleIcon or ''), {title: postText}) }}</span>
</li>
{%- endfor %}
</ul>
</div>
<div id="rcomment">
<h2>{{__('index.recent_comments')}}</h2>
</div>
</div>
{% endmacro %}

View File

@@ -1,5 +1,5 @@
{% import '_macro/sidebar.njk' as sidebar with context %}
{% import '_macro/breadcrumb.njk' as breadcrumb with context %}
{% import '_macro/widget.njk' as widget with context %}
<!DOCTYPE html>
<html lang="{{ config.language }}">
@@ -84,27 +84,7 @@
</main>
<footer id="footer">
<div class="inner">
<div class="widgets">
<div class="rpost pjax">
<h2>{{__('index.random_posts')}}</h2>
<ul>
{%- set posts = site.posts.shuffle().limit(10).toArray() %}
{%- for item in posts %}
{%- if item.link %}
{%- set postTitleIcon = '<i class="ic i-link-alt"></i>' %}
{%- endif %}
<li class="item">
{{ breadcrumb.render(item, false) }}
{%- set postText = item.title or item.link or __('post.untitled') %}
<span>{{ _url(item.link or item.path, postText + (postTitleIcon or ''), {title: postText}) }}</span>
</li>
{%- endfor %}
</ul>
</div>
<div id="rcomment">
<h2>{{__('index.recent_comments')}}</h2>
</div>
</div>
{{ widget.render() }}
{{ partial('_partials/footer.njk', {}, {cache: true}) }}
</div>
</footer>