Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use nunjucks-compatible syntax & operator #1068

Merged
merged 13 commits into from
Sep 1, 2019
11 changes: 5 additions & 6 deletions layout/_layout.swig
Original file line number Diff line number Diff line change
Expand Up @@ -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' %}
Expand All @@ -19,7 +19,6 @@
{% include '_partials/head/head-unique.swig' %}
{{- next_inject('head') }}
<title>{% block title %}{% endblock %}</title>
<meta name="generator" content="Hexo {{ hexo_env('version') }}">
{{ partial('_third-party/analytics/index.swig', {}, {cache: theme.cache.enable}) }}
{{ partial('_scripts/noscript.swig', {}, {cache: theme.cache.enable}) }}
</head>
Expand All @@ -37,7 +36,7 @@
<main id="main" class="main">
<div class="main-inner">
<div class="content-wrap">
{%- if theme.scheme === 'Pisces' || theme.scheme === 'Gemini' %}
{%- if theme.scheme === 'Pisces' or theme.scheme === 'Gemini' %}
{% include '_partials/header/sub-menu.swig' %}
{%- endif %}
<div id="content" class="content">
Expand Down
10 changes: 5 additions & 5 deletions layout/_macro/post-collapse.swig
Original file line number Diff line number Diff line change
@@ -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 %}
<div class="collection-year">
<{%- if theme.seo %}h2{% else %}h1{%- endif %} class="collection-header">{{ year }}</{%- if theme.seo %}h2{% else %}h1{%- endif %}>
<{%- if theme.seo %}h2{% else %}h1{%- endif %} class="collection-header">{{ current_year }}</{%- if theme.seo %}h2{% else %}h1{%- endif %}>
</div>
{%- endif %}

Expand Down
12 changes: 6 additions & 6 deletions layout/_macro/post.swig
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

{%- if post.header !== false %}
<header class="post-header">
<{%- 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 %}
Expand Down Expand Up @@ -54,7 +54,7 @@
</span>
<span class="post-meta-item-text">{{ __('post.posted') }}</span>

{%- 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) %}
Expand All @@ -66,10 +66,10 @@
</span>
{%- 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 %}
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-check-o"></i>
Expand Down Expand Up @@ -174,7 +174,7 @@
{#################}
{### POST BODY ###}
{#################}
<div class="post-body{%- if post.direction && post.direction.toLowerCase() === 'rtl' %} rtl{%- endif %}" itemprop="articleBody">
<div class="post-body{%- if post.direction and post.direction.toLowerCase() === 'rtl' %} rtl{%- endif %}" itemprop="articleBody">

{# Gallery support #}
{%- if post.photos and post.photos.length %}
Expand Down
2 changes: 1 addition & 1 deletion layout/_partials/analytics/lean-analytics.swig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{%- if theme.leancloud_visitors.enable and !theme.valine.visitor %}
{%- if theme.leancloud_visitors.enable and not theme.valine.visitor %}
{# custom analytics part create by xiamo; edited by LEAFERx #}
<script{{ pjax }}>
function leancloudSelector(url) {
Expand Down
2 changes: 1 addition & 1 deletion layout/_partials/footer.swig
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<span class="with-love" id="animate">
<i class="fa fa-{{ theme.footer.icon.name }}"></i>
</span>
<span class="author" itemprop="copyrightHolder">{{ theme.footer.copyright || author }}</span>
<span class="author" itemprop="copyrightHolder">{{ theme.footer.copyright or author }}</span>

{%- if config.symbols_count_time.total_symbols %}
<span class="post-meta-divider">|</span>
Expand Down
11 changes: 2 additions & 9 deletions layout/_partials/head/head-unique.swig
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
{{ open_graph() }}

{%- if theme.rss === '' and config.feed and config.feed.path %}
{%- set theme.rss = config.feed.path %}
{%- endif %}
{%- if theme.rss %}
<link rel="alternate" href="{{ url_for(theme.rss) }}" title="{{ title }}" type="application/atom+xml">
{%- endif %}

{%- if theme.canonical %}
{%- set without_index = url.replace('index.html', '') %}
{%- set without_html = without_index.replace('.html', '') %}
{%- set without_index = url | replace('index.html', '') %}
{%- set without_html = without_index | replace('.html', '') %}
<link rel="canonical" href="{{ without_html }}">
{%- endif %}

Expand Down
9 changes: 8 additions & 1 deletion layout/_partials/head/head.swig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="{{ theme.android_chrome_color }}">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="generator" content="Hexo {{ hexo_env('version') }}">

{%- if theme.favicon.apple_touch_icon %}
<link rel="apple-touch-icon" sizes="180x180" href="{{ url_for(theme.favicon.apple_touch_icon) }}?v={{ version }}">
Expand All @@ -22,6 +22,13 @@
<meta name="msapplication-config" content="{{ url_for(theme.favicon.ms_browserconfig) }}">
{%- endif %}

{%- if theme.rss === '' and config.feed.path %}
{%- set theme.rss = config.feed.path %}
{%- endif %}
{%- if theme.rss %}
<link rel="alternate" href="{{ url_for(theme.rss) }}" title="{{ title }}" type="application/atom+xml">
{%- endif %}

{%- if theme.disable_baidu_transformation %}
<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
Expand Down
4 changes: 2 additions & 2 deletions layout/_partials/header/index.swig
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{{ partial('_partials/header/brand.swig', {}, {cache: theme.cache.enable}) }}

{%- set hasSearch = theme.algolia_search.enable || theme.local_search.enable %}
{%- set hasSearch = theme.algolia_search.enable or theme.local_search.enable %}

<nav class="site-nav">
{{ partial('_partials/header/menu.swig', {}, {cache: theme.cache.enable}) }}

{%- if theme.scheme === 'Muse' || theme.scheme === 'Mist' %}
{%- if theme.scheme === 'Muse' or theme.scheme === 'Mist' %}
{% include 'sub-menu.swig' %}
{%- endif %}
</nav>
Expand Down
2 changes: 1 addition & 1 deletion layout/_partials/header/sub-menu.swig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{%- if not is_home() && not is_post() %}
{%- if not is_home() and not is_post() %}
{%- if theme.menu %}

{% import '../../_macro/menu/menu-item.swig' as menu_item %}
Expand Down
10 changes: 5 additions & 5 deletions layout/_partials/page/breadcrumb.swig
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
{%- set link = '' %}
<ul class="breadcrumb">
{%- for path in paths %}
{%- set current += 1 %}
{%- set current = current + 1 %}
{%- if path != 'index.html' %}
{%- if current == count - 1 and paths[count - 1] == 'index.html' %}
<li>{{ path | upper }}</li>
{% else %}
{%- if link == '' %}
{%- set link = '/' + path %}
{% else %}
{%- set link += '/' + path %}
{%- set link = link + '/' + path %}
{%- endif %}
{%- if path.indexOf('.html') == -1 %}
<li><a href="{{ url_for(link) }}/">{{ path | upper }}</a></li>
{%- if path.includes('.html') %}
<li>{{ path | replace('.html', '') | upper }}</li>
{% else %}
<li>{{ path.replace('.html', '') | upper }}</li>
<li><a href="{{ url_for(link) }}/">{{ path | upper }}</a></li>
{%- endif %}
{%- endif %}
{%- endif %}
Expand Down
4 changes: 2 additions & 2 deletions layout/_partials/post/post-copyright.swig
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
<ul class="post-copyright">
<li class="post-copyright-author">
<strong>{{ __('post.copyright.author') + __('symbol.colon') }} </strong>{#
#}{{ post.author || author }}{#
#}{{ post.author or author }}{#
#}</li>
<li class="post-copyright-link">
<strong>{{ __('post.copyright.link') + __('symbol.colon') }}</strong>
{%- set postURL = post.url || post.permalink %}
{%- set postURL = post.url or post.permalink %}
{{ next_url(postURL, postURL, {title: post.title}) }}
</li>
<li class="post-copyright-license">
Expand Down
4 changes: 2 additions & 2 deletions layout/_partials/post/post-related.swig
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
{%- if popular_post.date and popular_post.date != '' %}
<div class="popular-posts-date">{{ popular_post.date }}</div>
{%- endif %}
{%- if popular_post.img && popular_post.img != '' %}
{%- if popular_post.img and popular_post.img != '' %}
<div class="popular-posts-img"><img src="{{ popular_post.img }}"></div>
{%- endif %}
<div class="popular-posts-title"><a href="{{ popular_post.path }}" rel="bookmark">{{ popular_post.title }}</a></div>
{%- if popular_post.excerpt && popular_post.excerpt != '' %}
{%- if popular_post.excerpt and popular_post.excerpt != '' %}
<div class="popular-posts-excerpt"><p>{{ popular_post.excerpt }}</p></div>
{%- endif %}
</li>
Expand Down
2 changes: 1 addition & 1 deletion layout/_partials/post/post-reward.swig
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

{%- for name, image in theme.reward %}
{%- set builtin = ['wechatpay', 'alipay', 'bitcoin'] %}
{%- if builtin.indexOf(name) !== -1 %}
{%- if builtin.includes(name) %}
{%- set translation = __('reward.' + name) %}
{% else %}
{%- set translation = name %}
Expand Down
2 changes: 1 addition & 1 deletion layout/_third-party/comments/valine.swig
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ NexT.utils.getScript('{{ valine_uri }}', () => {
var GUEST = ['nick', 'mail', 'link'];
var guest = '{{ theme.valine.guest_info }}';
guest = guest.split(',').filter(item => {
return GUEST.indexOf(item) > -1;
return GUEST.includes(item);
});
new Valine({
el: '#comments',
Expand Down
2 changes: 1 addition & 1 deletion layout/_third-party/facebook-sdk.swig
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/{{ config.language|replace('-', '_') }}/sdk.js";
js.src = "//connect.facebook.net/{{ config.language | replace('-', '_') }}/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
Expand Down
2 changes: 1 addition & 1 deletion layout/_third-party/quicklink.swig
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
quicklink({
timeout: {{ theme.quicklink.timeout }},
priority: {{ theme.quicklink.priority }},
ignores: [uri => uri.includes('#'),uri => uri == '{{ url.replace('index.html', '') }}',{{ theme.quicklink.ignores }}]
ignores: [uri => uri.includes('#'),uri => uri == '{{ url | replace('index.html', '') }}',{{ theme.quicklink.ignores }}]
});
{%- if theme.quicklink.delay %}
});
Expand Down
2 changes: 1 addition & 1 deletion layout/page.swig
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
{#################}
{### PAGE BODY ###}
{#################}
<div class="post-body{%- if page.direction && page.direction.toLowerCase() === 'rtl' %} rtl{%- endif %}">
<div class="post-body{%- if page.direction and page.direction.toLowerCase() === 'rtl' %} rtl{%- endif %}">
{# tagcloud page support #}
{%- if page.type === 'tags' %}
<div class="tag-cloud">
Expand Down