Skip to content

Commit

Permalink
Cache sidebar site-overview (theme-next#971)
Browse files Browse the repository at this point in the history
* Move head point, it can be set cache in options

* cache site-overview
  • Loading branch information
jiangtj authored Jul 15, 2019
1 parent cc1fd52 commit 3a1dd62
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 143 deletions.
3 changes: 3 additions & 0 deletions layout/_layout.swig
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
<head>
{{ partial('_partials/head/head.swig', {}, {cache: theme.cache.enable}) }}
{% include '_partials/head/head-unique.swig' %}
{% for inject_item in theme.injects.head %}
{{ partial(inject_item.layout, inject_item.locals, inject_item.options) }}
{% endfor %}
<title>{% block title %}{% endblock %}</title>
{% include '_third-party/analytics/index.swig' %}
{{ partial('_scripts/noscript.swig', {}, {cache: theme.cache.enable}) }}
Expand Down
141 changes: 2 additions & 139 deletions layout/_macro/sidebar.swig
Original file line number Diff line number Diff line change
Expand Up @@ -25,146 +25,9 @@

<div class="site-overview-wrap sidebar-panel{% if not display_toc or toc(page.content).length <= 1 %} sidebar-panel-active{% endif %}">
<div class="site-overview">
<div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
{% if theme.avatar.url %}
<img class="site-author-image" itemprop="image"
src="{{ url_for( theme.avatar.url | default(theme.images + '/avatar.gif') ) }}"
alt="{{ author }}"/>
{% endif %}
<p class="site-author-name" itemprop="name">{{ author }}</p>
<div class="site-description motion-element" itemprop="description">{{ description }}</div>
</div>

{% if theme.site_state %}
<nav class="site-state motion-element">
{% if config.archive_dir != '/' and site.posts.length > 0 %}
<div class="site-state-item site-state-posts">
{% if theme.menu.archives %}
<a href="{{ url_for(theme.menu.archives).split('||')[0] | trim }}">
{% else %}
<a href="{{ url_for(config.archive_dir) }}">
{% endif %}
<span class="site-state-item-count">{{ site.posts.length }}</span>
<span class="site-state-item-name">{{ __('state.posts') }}</span>
</a>
</div>
{% endif %}

{% if site.categories.length > 0 %}
{% set categoriesPageQuery = site.pages.find({type: 'categories'}, {lean: true}) %}
{% set hasCategoriesPage = categoriesPageQuery.length > 0 %}
<div class="site-state-item site-state-categories">
{% if hasCategoriesPage %}
{% if theme.menu.categories %}
<a href="{{ url_for(theme.menu.categories).split('||')[0] | trim }}">
{% else %}
<a href="{{ url_for(config.category_dir) + '/' }}">
{% endif %}
{% endif %}
{% set visibleCategories = 0 %}
{% for cat in site.categories %}
{% if cat.length %}{% set visibleCategories += 1 %}{% endif %}
{% endfor %}
<span class="site-state-item-count">{{ visibleCategories }}</span>
<span class="site-state-item-name">{{ __('state.categories') }}</span>
{% if hasCategoriesPage %}</a>{% endif %}
</div>
{% endif %}

{% if site.tags.length > 0 %}
{% set tagsPageQuery = site.pages.find({type: 'tags'}, {lean: true}) %}
{% set hasTagsPage = tagsPageQuery.length > 0 %}
<div class="site-state-item site-state-tags">
{% if hasTagsPage %}
{% if theme.menu.tags %}
<a href="{{ url_for(theme.menu.tags).split('||')[0] | trim }}">
{% else %}
<a href="{{ url_for(config.tag_dir) + '/' }}">
{% endif %}
{% endif %}
{% set visibleTags = 0 %}
{% for tag in site.tags %}
{% if tag.length %}{% set visibleTags += 1 %}{% endif %}
{% endfor %}
<span class="site-state-item-count">{{ visibleTags }}</span>
<span class="site-state-item-name">{{ __('state.tags') }}</span>
{% if hasTagsPage %}</a>{% endif %}
</div>
{% endif %}
</nav>
{% endif %}

{% if theme.rss %}
<div class="feed-link motion-element">
<a href="{{ url_for(theme.rss) }}" rel="alternate">
<i class="fa fa-rss"></i>
RSS
</a>
</div>
{% endif %}

{% if theme.chat.enable and theme.chat.service !== '' %}
<div class="chat motion-element">
{% if theme.chat.service == 'chatra' and theme.chatra.enable %}
<a onclick="Chatra('openChat', true)">
{% endif %}
{% if theme.chat.service == 'tidio' and theme.tidio.enable %}
<a onclick="tidioChatApi.open();">
{% endif %}
{% if theme.chat.icon %}<i class="fa fa-{{ theme.chat.icon }}"></i>{% endif %}
{{ theme.chat.text }}
</a>
</div>
{% endif %}

{% if theme.social %}
<div class="links-of-author motion-element">
{% for name, link in theme.social %}
<span class="links-of-author-item">
{% set sidebarURL = link.split('||')[0] | trim %}
{% if not (theme.social_icons.enable) or (not theme.social_icons.icons_only) %}
{% set sidebarText = name %}
{% endif %}
{% if theme.social_icons.enable %}
{% set sidebarIcon = '<i class="fa fa-fw fa-' + link.split('||')[1] | trim | default('globe') + '"></i>' %}
{% endif %}
{{ next_url(sidebarURL, sidebarIcon + sidebarText, {title: name + ' &rarr; ' + sidebarURL}) }}
</span>
{% endfor %}
</div>
{% endif %}

{% if theme.creative_commons.license and theme.creative_commons.sidebar %}
<div class="cc-license motion-element" itemprop="license">
{% set ccLanguage = theme.creative_commons.language %}
{% if theme.creative_commons.license === 'zero' %}
{% set ccType = 'publicdomain/zero/1.0/' + ccLanguage %}
{% else %}
{% set ccType = 'licenses/' + theme.creative_commons.license + '/4.0/' + ccLanguage %}
{% endif %}
{% set ccURL = 'https://creativecommons.org/' + ccType %}
{% set ccImage = '<img src="' + url_for(theme.images + '/cc-' + theme.creative_commons.license + '.svg') + '" alt="Creative Commons"/>' %}
{{ next_url(ccURL, ccImage, {class: 'cc-opacity'}) }}
</div>
{% endif %}

{# Blogroll #}
{% if theme.links %}
<div class="links-of-blogroll motion-element {{ "links-of-blogroll-" + theme.links_layout | default('inline') }}">
<div class="links-of-blogroll-title">
<i class="fa fa-fw fa-{{ theme.links_icon | default('globe') | lower }}"></i>
{{ theme.links_title }}
</div>
<ul class="links-of-blogroll-list">
{% for blogrollText, blogrollURL in theme.links %}
<li class="links-of-blogroll-item">
{{ next_url(blogrollURL, blogrollText, {title: blogrollURL}) }}
</li>
{% endfor %}
</ul>
</div>
{% endif %}

{{ partial('_partials/sidebar/site-overview.swig', {}, {cache: theme.cache.enable}) }}

{% for inject_item in theme.injects.sidebar %}
{{ partial(inject_item.layout, inject_item.locals, inject_item.options) }}
{% endfor %}
Expand Down
4 changes: 0 additions & 4 deletions layout/_partials/head/head.swig
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,3 @@
}
};
</script>

{% for inject_item in theme.injects.head %}
{{ partial(inject_item.layout, inject_item.locals, inject_item.options) }}
{% endfor %}
138 changes: 138 additions & 0 deletions layout/_partials/sidebar/site-overview.swig
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
<div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
{% if theme.avatar.url %}
<img class="site-author-image" itemprop="image"
src="{{ url_for( theme.avatar.url | default(theme.images + '/avatar.gif') ) }}"
alt="{{ author }}"/>
{% endif %}
<p class="site-author-name" itemprop="name">{{ author }}</p>
<div class="site-description motion-element" itemprop="description">{{ description }}</div>
</div>

{% if theme.site_state %}
<nav class="site-state motion-element">
{% if config.archive_dir != '/' and site.posts.length > 0 %}
<div class="site-state-item site-state-posts">
{% if theme.menu.archives %}
<a href="{{ url_for(theme.menu.archives).split('||')[0] | trim }}">
{% else %}
<a href="{{ url_for(config.archive_dir) }}">
{% endif %}
<span class="site-state-item-count">{{ site.posts.length }}</span>
<span class="site-state-item-name">{{ __('state.posts') }}</span>
</a>
</div>
{% endif %}

{% if site.categories.length > 0 %}
{% set categoriesPageQuery = site.pages.find({type: 'categories'}, {lean: true}) %}
{% set hasCategoriesPage = categoriesPageQuery.length > 0 %}
<div class="site-state-item site-state-categories">
{% if hasCategoriesPage %}
{% if theme.menu.categories %}
<a href="{{ url_for(theme.menu.categories).split('||')[0] | trim }}">
{% else %}
<a href="{{ url_for(config.category_dir) + '/' }}">
{% endif %}
{% endif %}
{% set visibleCategories = 0 %}
{% for cat in site.categories %}
{% if cat.length %}{% set visibleCategories += 1 %}{% endif %}
{% endfor %}
<span class="site-state-item-count">{{ visibleCategories }}</span>
<span class="site-state-item-name">{{ __('state.categories') }}</span>
{% if hasCategoriesPage %}</a>{% endif %}
</div>
{% endif %}

{% if site.tags.length > 0 %}
{% set tagsPageQuery = site.pages.find({type: 'tags'}, {lean: true}) %}
{% set hasTagsPage = tagsPageQuery.length > 0 %}
<div class="site-state-item site-state-tags">
{% if hasTagsPage %}
{% if theme.menu.tags %}
<a href="{{ url_for(theme.menu.tags).split('||')[0] | trim }}">
{% else %}
<a href="{{ url_for(config.tag_dir) + '/' }}">
{% endif %}
{% endif %}
{% set visibleTags = 0 %}
{% for tag in site.tags %}
{% if tag.length %}{% set visibleTags += 1 %}{% endif %}
{% endfor %}
<span class="site-state-item-count">{{ visibleTags }}</span>
<span class="site-state-item-name">{{ __('state.tags') }}</span>
{% if hasTagsPage %}</a>{% endif %}
</div>
{% endif %}
</nav>
{% endif %}

{% if theme.rss %}
<div class="feed-link motion-element">
<a href="{{ url_for(theme.rss) }}" rel="alternate">
<i class="fa fa-rss"></i>RSS
</a>
</div>
{% endif %}

{% if theme.chat.enable and theme.chat.service !== '' %}
<div class="chat motion-element">
{% if theme.chat.service == 'chatra' and theme.chatra.enable %}
<a onclick="Chatra('openChat', true)">
{% endif %}
{% if theme.chat.service == 'tidio' and theme.tidio.enable %}
<a onclick="tidioChatApi.open();">
{% endif %}
{% if theme.chat.icon %}<i class="fa fa-{{ theme.chat.icon }}"></i>{% endif %}
{{ theme.chat.text }}
</a>
</div>
{% endif %}

{% if theme.social %}
<div class="links-of-author motion-element">
{% for name, link in theme.social %}
<span class="links-of-author-item">
{% set sidebarURL = link.split('||')[0] | trim %}
{% if not (theme.social_icons.enable) or (not theme.social_icons.icons_only) %}
{% set sidebarText = name %}
{% endif %}
{% if theme.social_icons.enable %}
{% set sidebarIcon = '<i class="fa fa-fw fa-' + link.split('||')[1] | trim | default('globe') + '"></i>' %}
{% endif %}
{{ next_url(sidebarURL, sidebarIcon + sidebarText, {title: name + ' &rarr; ' + sidebarURL}) }}
</span>
{% endfor %}
</div>
{% endif %}

{% if theme.creative_commons.license and theme.creative_commons.sidebar %}
<div class="cc-license motion-element" itemprop="license">
{% set ccLanguage = theme.creative_commons.language %}
{% if theme.creative_commons.license === 'zero' %}
{% set ccType = 'publicdomain/zero/1.0/' + ccLanguage %}
{% else %}
{% set ccType = 'licenses/' + theme.creative_commons.license + '/4.0/' + ccLanguage %}
{% endif %}
{% set ccURL = 'https://creativecommons.org/' + ccType %}
{% set ccImage = '<img src="' + url_for(theme.images + '/cc-' + theme.creative_commons.license + '.svg') + '" alt="Creative Commons"/>' %}
{{ next_url(ccURL, ccImage, {class: 'cc-opacity'}) }}
</div>
{% endif %}

{# Blogroll #}
{% if theme.links %}
<div class="links-of-blogroll motion-element {{ "links-of-blogroll-" + theme.links_layout | default('inline') }}">
<div class="links-of-blogroll-title">
<i class="fa fa-fw fa-{{ theme.links_icon | default('globe') | lower }}"></i>
{{ theme.links_title }}
</div>
<ul class="links-of-blogroll-list">
{% for blogrollText, blogrollURL in theme.links %}
<li class="links-of-blogroll-item">
{{ next_url(blogrollURL, blogrollText, {title: blogrollURL}) }}
</li>
{% endfor %}
</ul>
</div>
{% endif %}

0 comments on commit 3a1dd62

Please sign in to comment.