Skip to content

Commit

Permalink
Optimize the rendering of posts (#1075)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenjoezhang authored Aug 7, 2019
1 parent 73697d8 commit 6c03d3d
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 111 deletions.
153 changes: 55 additions & 98 deletions layout/_macro/post.swig
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@
{%- endif %}
</div>

{#####################}
{### END POST BODY ###}
{#####################}

{%- if theme.related_posts.enable and (theme.related_posts.display_in_home or not is_index) %}
{% include '../_partials/post/post-related.swig' with { post: post } %}
{%- endif %}
Expand All @@ -269,117 +273,70 @@
{%- for inject_item in theme.injects.postBodyEnd %}
{{ partial(inject_item.layout, inject_item.locals, inject_item.options) }}
{%- endfor %}
{%- endif %}

{#####################}
{### END POST BODY ###}
{#####################}

{%- if theme.wechat_subscriber.enable and not is_index %}
{% include '../_partials/post/wechat-subscriber.swig' %}
{%- endif %}
{%- if theme.wechat_subscriber.enable %}
{{ partial('../_partials/post/wechat-subscriber.swig', {}, {cache: theme.cache.enable}) }}
{%- endif %}

{%- if post.reward === undefined and theme.reward_settings.enable %}
{%- set reward_able = true %}
{% else %}
{%- set reward_able = post.reward %}
{%- endif %}
{%- if reward_able and not is_index %}
<div>
{% include '../_partials/post/reward.swig' %}
</div>
{%- endif %}
{%- if post.reward === undefined and theme.reward_settings.enable %}
{%- set reward_able = true %}
{% else %}
{%- set reward_able = post.reward %}
{%- endif %}
{%- if reward_able %}
{{ partial('../_partials/post/post-reward.swig', {}, {cache: theme.cache.enable}) }}
{%- endif %}

{%- if theme.creative_commons.license and theme.creative_commons.post and not is_index %}
<div>
{%- if theme.creative_commons.license and theme.creative_commons.post %}
{% include '../_partials/post/post-copyright.swig' with { post: post } %}
</div>
{%- endif %}

<footer class="post-footer">
{%- if post.tags and post.tags.length and not is_index %}
{%- if theme.tag_icon %}
{%- set tag_indicate = '<i class="fa fa-tag"></i>' %}
{% else %}
{%- set tag_indicate = '#' %}
{%- endif %}
<div class="post-tags">
{%- for tag in post.tags %}
<a href="{{ url_for(tag.path) }}" rel="tag">{{ tag_indicate }} {{ tag.name }}</a>
{%- endfor %}
</div>
{%- endif %}

{%- if not is_index %}
{%- if theme.rating.enable or (theme.vkontakte_api.enable and theme.vkontakte_api.like) or (theme.facebook_sdk.enable and theme.facebook_sdk.like_button) or theme.likely.enable or (theme.needmoreshare2.enable and theme.needmoreshare2.postbottom.enable) %}
<div class="post-widgets">
{%- if theme.rating.enable %}
<div class="wp_rating">
<div id="wpac-rating"></div>
</div>
{%- endif %}

{%- if (theme.vkontakte_api.enable and theme.vkontakte_api.like) or (theme.facebook_sdk.enable and theme.facebook_sdk.like_button) %}
<div class="social-like">
{%- if theme.vkontakte_api.enable and theme.vkontakte_api.like %}
<div class="vk_like">
<span id="vk_like"></span>
</div>
{%- endif %}

{%- if theme.facebook_sdk.enable and theme.facebook_sdk.like_button %}
<div class="fb_like">
<div class="fb-like" data-layout="button_count" data-share="true"></div>
</div>
{%- endif %}
<footer class="post-footer">
{%- if post.tags and post.tags.length %}
{%- if theme.tag_icon %}
{%- set tag_indicate = '<i class="fa fa-tag"></i>' %}
{% else %}
{%- set tag_indicate = '#' %}
{%- endif %}
<div class="post-tags">
{%- for tag in post.tags %}
<a href="{{ url_for(tag.path) }}" rel="tag">{{ tag_indicate }} {{ tag.name }}</a>
{%- endfor %}
</div>
{%- endif %}

{%- if theme.likely.enable or (theme.needmoreshare2.enable and theme.needmoreshare2.postbottom.enable) %}
<div class="social-share">
{%- if theme.likely.enable %}
{% include '../_partials/share/likely.swig' %}
{%- endif %}
{%- if theme.needmoreshare2.enable and theme.needmoreshare2.postbottom.enable %}
<div id="needsharebutton-postbottom">
<span class="btn">
<i class="fa fa-share-alt" aria-hidden="true"></i>
</span>
</div>
{%- endif %}
</div>
{%- endif %}
</div>
{%- endif %}
{%- endif %}
{{ partial('../_partials/post/post-footer.swig', {}, {cache: theme.cache.enable}) }}

{%- if not is_index and (post.prev or post.next) %}
<div class="post-nav">
<div class="post-nav-next post-nav-item">
{%- if post.next %}
<a href="{{ url_for(post.next.path) }}" rel="next" title="{{ post.next.title }}">
<i class="fa fa-chevron-left"></i> {{ post.next.title }}
</a>
{%- endif %}
</div>
{%- if post.prev or post.next %}
<div class="post-nav">
<div class="post-nav-next post-nav-item">
{%- if post.next %}
<a href="{{ url_for(post.next.path) }}" rel="next" title="{{ post.next.title }}">
<i class="fa fa-chevron-left"></i> {{ post.next.title }}
</a>
{%- endif %}
</div>

<span class="post-nav-divider"></span>
<span class="post-nav-divider"></span>

<div class="post-nav-prev post-nav-item">
{%- if post.prev %}
<a href="{{ url_for(post.prev.path) }}" rel="prev" title="{{ post.prev.title }}">
{{ post.prev.title }} <i class="fa fa-chevron-right"></i>
</a>
{%- endif %}
<div class="post-nav-prev post-nav-item">
{%- if post.prev %}
<a href="{{ url_for(post.prev.path) }}" rel="prev" title="{{ post.prev.title }}">
{{ post.prev.title }} <i class="fa fa-chevron-right"></i>
</a>
{%- endif %}
</div>
</div>
</div>
{%- endif %}

{%- set isLast = loop.index % post.per_page === 0 %}
{%- if is_index and not isLast %}
<div class="post-eof"></div>
{%- endif %}
</footer>
{%- endif %}
</footer>
{% else %}
<footer class="post-footer">
{%- set isLast = loop.index % post.per_page === 0 %}
{%- if not isLast %}
<div class="post-eof"></div>
{%- endif %}
</footer>
{%- endif %}
</div>
{######################}
{### END POST BLOCK ###}
Expand Down
2 changes: 2 additions & 0 deletions layout/_partials/post/post-copyright.swig
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
{%- endif %}
{%- set ccURL = 'https://creativecommons.org/' + ccType %}

<div>
<ul class="post-copyright">
<li class="post-copyright-author">
<strong>{{ __('post.copyright.author') + __('symbol.colon') }} </strong>{#
Expand All @@ -24,3 +25,4 @@
#}{{ __('post.copyright.license_content', next_url(ccURL, ccIcon + ccText)) }}{#
#}</li>
</ul>
</div>
50 changes: 50 additions & 0 deletions layout/_partials/post/post-footer.swig
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{%- if theme.rating.enable or (theme.vkontakte_api.enable and theme.vkontakte_api.like) or (theme.facebook_sdk.enable and theme.facebook_sdk.like_button) or theme.likely.enable or (theme.needmoreshare2.enable and theme.needmoreshare2.postbottom.enable) %}
<div class="post-widgets">
{%- if theme.rating.enable %}
<div class="wp_rating">
<div id="wpac-rating"></div>
</div>
{%- endif %}

{%- if (theme.vkontakte_api.enable and theme.vkontakte_api.like) or (theme.facebook_sdk.enable and theme.facebook_sdk.like_button) %}
<div class="social-like">
{%- if theme.vkontakte_api.enable and theme.vkontakte_api.like %}
<div class="vk_like">
<span id="vk_like"></span>
</div>
{%- endif %}

{%- if theme.facebook_sdk.enable and theme.facebook_sdk.like_button %}
<div class="fb_like">
<div class="fb-like" data-layout="button_count" data-share="true"></div>
</div>
{%- endif %}
</div>
{%- endif %}

{%- if theme.likely.enable or (theme.needmoreshare2.enable and theme.needmoreshare2.postbottom.enable) %}
<div class="social-share">
{%- if theme.likely.enable %}
{%- if theme.likely.look == 'normal' %}
{%- set likely_look = 'likely' %}
{% else %}
{%- set likely_look = 'likely likely-' + theme.likely.look %}
{%- endif %}

<div class="{{ likely_look }}">
{%- for x in theme.likely.networks %}
<div class="{{ loop.key }}">{{ x }}</div>
{%- endfor %}
</div>
{%- endif %}
{%- if theme.needmoreshare2.enable and theme.needmoreshare2.postbottom.enable %}
<div id="needsharebutton-postbottom">
<span class="btn">
<i class="fa fa-share-alt" aria-hidden="true"></i>
</span>
</div>
{%- endif %}
</div>
{%- endif %}
</div>
{%- endif %}
File renamed without changes.
3 changes: 3 additions & 0 deletions layout/_partials/share/index.swig
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{%- if theme.add_this_id %}
{% include 'add-this.swig' %}
{%- endif %}
{%- if theme.likely.enable %}
{% include 'likely.swig' %}
{%- endif %}
{%- if theme.needmoreshare2.enable %}
{% include 'needsharebutton.swig' %}
{%- endif %}
13 changes: 0 additions & 13 deletions layout/_partials/share/likely.swig
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
{%- if theme.likely.look == 'normal' %}
{%- set likely_look = 'likely' %}
{% else %}
{%- set likely_look = 'likely likely-' + theme.likely.look %}
{%- endif %}

<div class="{{ likely_look }}">
{%- for x in theme.likely.networks %}
<div class="{{ loop.key }}">{{ x }}</div>
{%- endfor %}
</div>

{%- set likely_js_url = '//cdn.jsdelivr.net/npm/ilyabirman-likely@2/release/likely.js' %}
{%- if theme.vendors.likely_js %}
{%- set likely_js_url = theme.vendors.likely_js %}
{%- endif %}
<script src="{{ likely_js_url }}"></script>

0 comments on commit 6c03d3d

Please sign in to comment.