Skip to content

Commit

Permalink
Add next_inject helper (theme-next#1098)
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangtj authored Aug 16, 2019
1 parent fd69de6 commit ef0a544
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 22 deletions.
8 changes: 2 additions & 6 deletions layout/_layout.swig
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
<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 %}
{{- next_inject('head') }}
<title>{% block title %}{% endblock %}</title>
{% include '_third-party/analytics/index.swig' %}
{{ partial('_scripts/noscript.swig', {}, {cache: theme.cache.enable}) }}
Expand Down Expand Up @@ -96,9 +94,7 @@

{% block script_extra %}{% endblock %}

{%- for inject_item in theme.injects.bodyEnd %}
{{ partial(inject_item.layout, inject_item.locals, inject_item.options) }}
{%- endfor %}
{{- next_inject('bodyEnd') }}

{%- if theme.pjax %}
</div>
Expand Down
8 changes: 2 additions & 6 deletions layout/_macro/post.swig
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,7 @@
</span>
{%- endif %}

{%- for inject_item in theme.injects.postMeta %}
{{ partial(inject_item.layout, inject_item.locals, inject_item.options) }}
{%- endfor %}
{{- next_inject('postMeta') }}

{%- if config.symbols_count_time.symbols %}
{%- if theme.symbols_count_time.separated_meta %}<br>{%- endif %}
Expand Down Expand Up @@ -255,9 +253,7 @@
{%- endif %}

{%- if not is_index %}
{%- for inject_item in theme.injects.postBodyEnd %}
{{ partial(inject_item.layout, inject_item.locals, inject_item.options) }}
{%- endfor %}
{{- next_inject('postBodyEnd') }}

{%- if theme.wechat_subscriber.enable %}
{{ partial('../_partials/post/wechat-subscriber.swig', {}, {cache: theme.cache.enable}) }}
Expand Down
7 changes: 3 additions & 4 deletions layout/_macro/sidebar.swig
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@
<div class="site-overview">

{{ 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 %}

{{- next_inject('sidebar') }}

</div>
</div>

Expand Down
4 changes: 1 addition & 3 deletions layout/_partials/footer.swig
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,4 @@
#}</div>
{%- endif %}

{%- for inject_item in theme.injects.footer %}
{{ partial(inject_item.layout, inject_item.locals, inject_item.options) }}
{%- endfor %}
{{- next_inject('footer') }}
4 changes: 1 addition & 3 deletions layout/_partials/header/index.swig
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,4 @@
</div>
{%- endif %}

{%- for inject_item in theme.injects.header %}
{{ partial(inject_item.layout, inject_item.locals, inject_item.options) }}
{%- endfor %}
{{- next_inject('header') }}
9 changes: 9 additions & 0 deletions scripts/helpers/next-inject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* global hexo */

'use strict';

hexo.extend.helper.register('next_inject', function(point) {
return hexo.theme.config.injects[point]
.map(item => this.partial(item.layout, item.locals, item.options))
.join('');
});

0 comments on commit ef0a544

Please sign in to comment.