From abd45df7137525b3c0e6ba348ff83006d294905b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=B4=8D=C9=AA=E1=B4=8D=C9=AA?= <1119186082@qq.com> Date: Sun, 1 Sep 2019 10:22:18 +0800 Subject: [PATCH] Use nunjucks-compatible syntax & operator (#1068) * Replace && with and * Replace || with or * Replace ! with not * Use ES6 includes method --- layout/_layout.swig | 11 +++++------ layout/_macro/post-collapse.swig | 10 +++++----- layout/_macro/post.swig | 12 ++++++------ layout/_partials/analytics/lean-analytics.swig | 2 +- layout/_partials/footer.swig | 2 +- layout/_partials/head/head-unique.swig | 11 ++--------- layout/_partials/head/head.swig | 9 ++++++++- layout/_partials/header/index.swig | 4 ++-- layout/_partials/header/sub-menu.swig | 2 +- layout/_partials/page/breadcrumb.swig | 10 +++++----- layout/_partials/post/post-copyright.swig | 4 ++-- layout/_partials/post/post-related.swig | 4 ++-- layout/_partials/post/post-reward.swig | 2 +- layout/_third-party/comments/valine.swig | 2 +- layout/_third-party/facebook-sdk.swig | 2 +- layout/_third-party/quicklink.swig | 2 +- layout/page.swig | 2 +- 17 files changed, 45 insertions(+), 46 deletions(-) diff --git a/layout/_layout.swig b/layout/_layout.swig index 5e148adcf6..10ed81f2cb 100644 --- a/layout/_layout.swig +++ b/layout/_layout.swig @@ -4,10 +4,10 @@ {%- set version = next_env('version') %} {# Language & Config #} -{%- set title = __('title') !== 'title' && __('title') || config.title %} -{%- set subtitle = __('subtitle') !== 'subtitle' && __('subtitle') || config.subtitle %} -{%- set author = __('author') !== 'author' && __('author') || config.author %} -{%- set description = __('description') !== 'description' && __('description') || config.description %} +{%- set title = __('title') !== 'title' and __('title') or config.title %} +{%- set subtitle = __('subtitle') !== 'subtitle' and __('subtitle') or config.subtitle %} +{%- set author = __('author') !== 'author' and __('author') or config.author %} +{%- set description = __('description') !== 'description' and __('description') or config.description %} {%- if theme.pjax %} {%- set pjax = ' pjax' %} @@ -19,7 +19,6 @@ {% include '_partials/head/head-unique.swig' %} {{- next_inject('head') }} {% block title %}{% endblock %} - {{ partial('_third-party/analytics/index.swig', {}, {cache: theme.cache.enable}) }} {{ partial('_scripts/noscript.swig', {}, {cache: theme.cache.enable}) }} @@ -37,7 +36,7 @@
- {%- if theme.scheme === 'Pisces' || theme.scheme === 'Gemini' %} + {%- if theme.scheme === 'Pisces' or theme.scheme === 'Gemini' %} {% include '_partials/header/sub-menu.swig' %} {%- endif %}
diff --git a/layout/_macro/post-collapse.swig b/layout/_macro/post-collapse.swig index 7a028cce67..4b57a9dcae 100644 --- a/layout/_macro/post-collapse.swig +++ b/layout/_macro/post-collapse.swig @@ -1,13 +1,13 @@ {% macro render(posts) %} {%- for post in posts %} - {%- set year %} - {%- set post.year = date(post.date, 'YYYY') %} + {%- set current_year %} + {%- set year = date(post.date, 'YYYY') %} - {%- if post.year !== year %} - {%- set year = post.year %} + {%- if year !== current_year %} + {%- set current_year = year %}
- <{%- if theme.seo %}h2{% else %}h1{%- endif %} class="collection-header">{{ year }} + <{%- if theme.seo %}h2{% else %}h1{%- endif %} class="collection-header">{{ current_year }}
{%- endif %} diff --git a/layout/_macro/post.swig b/layout/_macro/post.swig index 651ac0b0d5..e777151812 100644 --- a/layout/_macro/post.swig +++ b/layout/_macro/post.swig @@ -17,7 +17,7 @@ {%- if post.header !== false %}
- <{%- if theme.seo %}h2{% else %}h1{%- endif %} class="post-title{%- if post.direction &&post.direction.toLowerCase() === 'rtl' %} rtl{%- endif %}" itemprop="name headline">{# + <{%- if theme.seo %}h2{% else %}h1{%- endif %} class="post-title{%- if post.direction and post.direction.toLowerCase() === 'rtl' %} rtl{%- endif %}" itemprop="name headline">{# #}{# Link posts #}{# #}{%- if post.link %} {%- if post.sticky > 0 %} @@ -54,7 +54,7 @@ - {%- if !date_diff && time_diff && theme.post_meta.updated_at.enable && theme.post_meta.updated_at.another_day %} + {%- if not date_diff and time_diff and theme.post_meta.updated_at.enable and theme.post_meta.updated_at.another_day %} {%- set create_title = __('post.created') + __('symbol.colon') + full_date(post.date) + ' / ' + __('post.modified') + __('symbol.colon') + time(post.updated) %} {% else %} {%- set create_title = __('post.created') + __('symbol.colon') + full_date(post.date) %} @@ -66,10 +66,10 @@ {%- endif %} - {%- if theme.post_meta.updated_at.enable && datetime_diff %} - {%- set display_updated = !theme.post_meta.updated_at.another_day || theme.post_meta.updated_at.another_day && date_diff %} + {%- if theme.post_meta.updated_at.enable and datetime_diff %} + {%- set display_updated = not theme.post_meta.updated_at.another_day or theme.post_meta.updated_at.another_day and date_diff %} - {%- if display_updated or !theme.post_meta.created_at %} + {%- if display_updated or not theme.post_meta.created_at %}