Skip to content

Commit

Permalink
feat(jekyll): support layout slots
Browse files Browse the repository at this point in the history
  • Loading branch information
ourai committed Apr 18, 2023
1 parent 585901d commit aaaf2e1
Show file tree
Hide file tree
Showing 19 changed files with 96 additions and 65 deletions.
5 changes: 0 additions & 5 deletions src/jekyll/_includes/ksio/head.html

This file was deleted.

File renamed without changes.
5 changes: 5 additions & 0 deletions src/jekyll/_includes/ksio/partials/head.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<meta charset="UTF-8">
{% include ksio/partials/meta/seo.html %}
{% include ksio/partials/meta/render.html %}
{% include ksio/partials/meta/feed.html %}
{% include ksio/partials/meta/brand.html %}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions src/jekyll/_includes/ksio/slots/aside.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% if page.ksio_slot_aside %}
<div class="Page-sidebar col-md-3">{% include "{{ page.ksio_slot_aside | replace: '.html', '' }}.html" %}</div>
{% else %}
{% ifhascontent sidebar %}
<div class="Page-sidebar col-md-3">{% contentblock sidebar %}</div>
{% endifhascontent %}
{% endif %}
18 changes: 18 additions & 0 deletions src/jekyll/_includes/ksio/slots/banner.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{% if page.ksio_slot_banner %}
{% include "{{ page.ksio_slot_banner | replace: '.html', '' }}.html" %}
{% else %}
{% assign banner = page.banner %}
{% if banner %}
<!-- 页面横幅 -->
<div class="Page-banner hidden-xs" style="background-image: url('{{ banner.url | asset_path }}');">
<figure class="sr-only">
<img src="{{ banner.url | asset_path }}" alt="{{ banner.description }}">
<figcaption>{{ banner.description }}</figcaption>
</figure>
</div>
{% else %}
{% ifhascontent post_banner %}
{% contentblock post_banner %}
{% endifhascontent %}
{% endif %}
{% endif %}
1 change: 1 addition & 0 deletions src/jekyll/_includes/ksio/slots/content.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% if page.ksio_slot_content %}{% include "{{ page.ksio_slot_content | replace: '.html', '' }}.html" %}{% else %}{{ content }}{% endif %}
9 changes: 9 additions & 0 deletions src/jekyll/_includes/ksio/slots/footer.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% if page.ksio_slot_footer %}
{% include "{{ page.ksio_slot_footer | replace: '.html', '' }}.html" %}
{% else %}
{% ifhascontent footer %}{% contentblock footer %}{% endifhascontent %}
{% ifnothascontent footer %}
{% include ksio/widgets/share.html %}
{% include ksio/widgets/toc.html %}
{% endifnothascontent %}
{% endif %}
26 changes: 26 additions & 0 deletions src/jekyll/_includes/ksio/slots/header.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{% if page.ksio_slot_header %}
{% include "{{ page.ksio_slot_header | replace: '.html', '' }}.html" %}
{% else %}
{% ifhascontent header_content %}
{% contentblock header_content %}
{% endifhascontent %}
{% ifnothascontent header_content %}
{% if page.ksio_slot_title %}
<h1 class="Article-title">{% include "{{ page.ksio_slot_title | replace: '.html', '' }}.html" %}</h1>
{% else %}
{% ifhascontent post_title %}
<h1 class="Article-title">{% contentblock post_title %}</h1>
{% endifhascontent %}
{% ifnothascontent post_title %}
<h1 class="Article-title">{{ page.title }}</h1>
{% endifnothascontent %}
{% endif %}
{% if page.ksio_slot_meta %}
{% include "{{ page.ksio_slot_meta | replace: '.html', '' }}.html" %}
{% else %}
{% ifhascontent post_meta %}
{% contentblock post_meta %}
{% endifhascontent %}
{% endif %}
{% endifnothascontent %}
{% endif %}
3 changes: 3 additions & 0 deletions src/jekyll/_includes/ksio/widgets/comment.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% if site.ksio.social.comment %}
{% if site.ksio.social.comment.disqus %}{% include ksio/widgets/disqus.html %}{% endif %}
{% endif %}
12 changes: 6 additions & 6 deletions src/jekyll/_includes/ksio/widgets/disqus.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{% assign comment_config = site.ksio.social.comment.disqus %}
{% if comment_config %}
{% if jekyll.environment == "production" %}
{% assign disqus_shortname = comment_config.shortname %}
{% else %}
{% assign disqus_shortname = "" %}
{% endif %}
{% if jekyll.environment == "production" %}
{% assign disqus_shortname = comment_config.shortname %}
{% else %}
{% assign disqus_shortname = "" %}
{% endif %}
{% if comment_config and disqus_shortname and disqus_shortname != "" %}
<div id="disqus_thread"></div>
{% if comment_config.proxy %}
{% javascript ksio/vendors/disqusjs.min %}
Expand Down
2 changes: 1 addition & 1 deletion src/jekyll/_includes/ksio/widgets/share.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% if site.ksio.social.share != false %}
{% if site.ksio.social.share != false and page.ksio_shareable != false %}
<div class="Widget Widget--share">
<div class="Widget-body">
<p>分享到<i class="fa fa-share-alt"></i></p>
Expand Down
18 changes: 9 additions & 9 deletions src/jekyll/_layouts/ksio/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@
<!-- 静态资源 -->
{% if site.ksio.social.comment.disqus.proxy %}{% stylesheet ksio/vendors/disqusjs.min %}{% endif %}
{% stylesheet global %}
{% if layout.css %}
{% for css in layout.css %}{{ css | stylesheet }}{% endfor %}
{% endif %}
{% if page.css %}
{% for css in page.css %}{{ css | stylesheet }}{% endfor %}
{% endif %}
{% if layout.ksio_asset_css %}{% assign css_from_layout = layout.ksio_asset_css %}{% elsif layout.css %}{% assign css_from_layout = layout.css %}{% endif %}
{% if css_from_layout %}{% for css in css_from_layout %}{{ css | stylesheet }}{% endfor %}{% endif %}
{% if page.ksio_asset_css %}{% assign css_from_page = page.ksio_asset_css %}{% elsif page.css %}{% assign css_from_page = page.css %}{% endif %}
{% if css_from_page %}{% for css in css_from_page %}{{ css | stylesheet }}{% endfor %}{% endif %}
{% if jekyll.environment == "production" and site.ksio.analytics == true and page.statistic != false %}
{% javascript statistic %}
{% endif %}
Expand All @@ -41,7 +39,7 @@
{% assign body_class = body_class | append: " " | append: page_body_class %}
{% endif %}
{% endifnothascontent %}
{% if page.banner %}
{% if page.ksio_slot_banner or page.banner %}
{% assign body_class = body_class | append: " " | append: "has-headerImage" %}
{% else %}
{% ifhascontent post_banner %}
Expand All @@ -50,7 +48,9 @@
{% endif %}
<body class="{{ body_class }}" itemscope itemtype="http:https://schema.org/WebPage">
{{ content }}
{% if layout.js %}{% for js in layout.js %}{{ js | javascript }}{% endfor %}{% endif %}
{% if page.js %}{% for js in page.js %}{{ js | javascript }}{% endfor %}{% endif %}
{% if layout.ksio_asset_js %}{% assign js_from_layout = layout.ksio_asset_js %}{% elsif layout.js %}{% assign js_from_layout = layout.js %}{% endif %}
{% if js_from_layout %}{% for js in js_from_layout %}{{ js | javascript }}{% endfor %}{% endif %}
{% if page.ksio_asset_js %}{% assign js_from_page = page.ksio_asset_js %}{% elsif page.js %}{% assign js_from_page = page.js %}{% endif %}
{% if js_from_page %}{% for js in js_from_page %}{{ js | javascript }}{% endfor %}{% endif %}
</body>
</html>
4 changes: 2 additions & 2 deletions src/jekyll/_layouts/ksio/doc.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
- ksio/components
---

{% include {{ site.ksio.header.partial | default: "ksio/header.html" }} %}
{% include {{ site.ksio.header.partial | default: "ksio/partials/header.html" }} %}
<div class="Page-content">
{% assign repo = site.data.local.repos[page.repo] %}
{% assign url_parts = page.id | split: "/" %}
Expand All @@ -30,7 +30,7 @@ <h1 class="Article-title">{{ page.title }}</h1>
{% include ksio/widgets/toc.html %}
</footer>
</article>
{% include {{ site.ksio.footer.partial | default: "ksio/footer.html" }} %}
{% include {{ site.ksio.footer.partial | default: "ksio/partials/footer.html" }} %}
</main>
</div>

Expand Down
51 changes: 9 additions & 42 deletions src/jekyll/_layouts/ksio/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,17 @@
- ksio/components
---

{% include {{ site.ksio.header.partial | default: "ksio/header.html" }} %}
{% include {{ site.ksio.header.partial | default: "ksio/partials/header.html" }} %}
<main class="Page-content">
{% assign banner = page.banner %}
{% if banner %}
<!-- 页面横幅 -->
<div class="Page-banner hidden-xs" style="background-image: url('{{ banner.url | asset_path }}');">
<figure class="sr-only">
<img src="{{ banner.url | asset_path }}" alt="{{ banner.description }}">
<figcaption>{{ banner.description }}</figcaption>
</figure>
</div>
{% else %}
{% ifhascontent post_banner %}
{% contentblock post_banner %}
{% endifhascontent %}
{% endif %}
{% include ksio/slots/banner.html %}
<!-- 内容主体 -->
<div class="container">
<article class="Page-main Article">
<header class="Article-header">
{% ifhascontent header_content %}
{% contentblock header_content %}
{% endifhascontent %}

{% ifnothascontent header_content %}
{% ifhascontent post_title %}
<h1 class="Article-title">{% contentblock post_title %}</h1>
{% endifhascontent %}

{% ifnothascontent post_title %}
<h1 class="Article-title">{{ page.title }}</h1>
{% endifnothascontent %}

{% ifhascontent post_meta %}
{% contentblock post_meta %}
{% endifhascontent %}
{% endifnothascontent %}
{% include ksio/slots/header.html %}
</header>
<div class="Article-content col-md-9">{{ content }}</div>
{% ifhascontent footer %}
<footer class="Article-footer col-md-3">{% contentblock footer %}</footer>
{% endifhascontent %}
<div class="Article-content col-md-9">{% include ksio/slots/content.html %}</div>
<footer class="Article-footer col-md-3">{% include ksio/slots/footer.html %}</footer>
{% if page.siblings == true %}
<!-- 相邻文章 -->
<nav class="Article-siblings LightBox col-md-9">
Expand Down Expand Up @@ -78,14 +47,12 @@ <h3>{{ sibling.title }}</h3>
</ul>
</nav>
{% endif %}
{% if page.comments == true %}
{% if site.ksio.social.comment and page.comments == true %}
<!-- 评论区 -->
<div class="Article-comments col-md-9">{% include ksio/widgets/disqus.html %}</div>
<div class="Article-comments col-md-9">{% include ksio/widgets/comment.html %}</div>
{% endif %}
</article>
{% ifhascontent sidebar %}
<div class="Page-sidebar col-md-3">{% contentblock sidebar %}</div>
{% endifhascontent %}
{% include ksio/slots/aside.html %}
</div>
</main>
{% include {{ site.ksio.footer.partial | default: "ksio/footer.html" }} %}
{% include {{ site.ksio.footer.partial | default: "ksio/partials/footer.html" }} %}

0 comments on commit aaaf2e1

Please sign in to comment.