Skip to content

Commit

Permalink
feat(jekyll): specific page slots
Browse files Browse the repository at this point in the history
  • Loading branch information
ourai committed Apr 19, 2023
1 parent 493da6a commit 170f102
Show file tree
Hide file tree
Showing 22 changed files with 164 additions and 156 deletions.
4 changes: 2 additions & 2 deletions man/cookbook/apis/site-config/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ interface CopyrightPeriod {
| 属性名 | 值类型/可选值 | 默认值 | 说明 |
| --- | --- | --- | --- |
| `links` | `Link[]` | - | 页面底部链接 |
| `partial` | `string` | `'ksio/footer.html'` | 预置布局模板中页脚部分,可指定自定义的替换主题预置的 |
| `partial` | `string` | `'ksio/partials/footer.html'` | 预置布局模板中页脚部分,可指定自定义的替换主题预置的 |

## `header`

Expand All @@ -77,7 +77,7 @@ interface CopyrightPeriod {
| --- | --- | --- | --- |
| `navbar` | `HeaderNavBar` | - | 页头导航栏,[详见下方](#navbar) |
| `navs` | `Link[]` | - | 页面头部导航 |
| `partial` | `string` | `'ksio/header.html'` | 预置布局模板中页头部分,可指定自定义的替换主题预置的 |
| `partial` | `string` | `'ksio/partials/header.html'` | 预置布局模板中页头部分,可指定自定义的替换主题预置的 |

### `navbar`

Expand Down
1 change: 0 additions & 1 deletion src/hexo/source/posts.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: 博客
ksio_seo_role: writer
ksio_slot_banner: _ksio/pages/posts/banner
ksio_slot_content: _ksio/pages/posts/content
ksio_slot_footer: _ksio/pages/posts/footer
Expand Down
1 change: 1 addition & 0 deletions src/jekyll/_assets/stylesheets/local/pages/doc.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "../../ksio/pages/doc";
1 change: 1 addition & 0 deletions src/jekyll/_assets/stylesheets/local/pages/post.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "../../ksio/pages/post";
1 change: 1 addition & 0 deletions src/jekyll/_assets/stylesheets/local/pages/posts.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "../../ksio/pages/posts";
6 changes: 3 additions & 3 deletions src/jekyll/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ defaults:
values:
layout: ksio/doc
css:
- ksio/pages/post
- ksio/pages/doc
- local/pages/post
- local/pages/doc
js:
- ksio/initializers/time
- ksio/initializers/lazyload
Expand All @@ -90,7 +90,7 @@ defaults:
values:
layout: ksio/post
css:
- ksio/pages/post
- local/pages/post
js:
- ksio/initializers/time
- ksio/initializers/lazyload
Expand Down
1 change: 1 addition & 0 deletions src/jekyll/_includes/ksio/pages/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>孩子,迷路了吧?来让蜀黍<a href="{{ '/' | prepend: site.baseurl | prepend: site.url }}">送你回家</a></p>
7 changes: 7 additions & 0 deletions src/jekyll/_includes/ksio/pages/posts/banner.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% assign banner_url = "ksio/banners/blog" | asset_path %}
<div class="Page-banner is-translucent hidden-xs" style="background-image: url('{{ banner_url }}');">
<figure class="sr-only">
<img src="{{ banner_url }}" alt="博客文章">
<figcaption>博客文章</figcaption>
</figure>
</div>
98 changes: 98 additions & 0 deletions src/jekyll/_includes/ksio/pages/posts/content.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{% assign posts = site.posts %}
{% if posts.size > 0 %}
{% assign first_post = posts.first %}
<!-- 最新文章 -->
<p>最近的一篇文章发表于 <time datetime="{{ first_post.date | date_to_xmlschema }}" class="u-bold">{{ first_post.date | date: "%Y 年 %-m 月 %-d 日" }}</time>——</p>
<blockquote>
<p>{{ first_post.content | markdownify | strip_html | strip_newlines | escape_once | truncate: 100, "..." }}</p>
<footer>{{ first_post.author.name }}</footer>
</blockquote>
<p>想看完整内容?快戳《<a href="{{ first_post.url }}">{{ first_post.title }}</a>》!(((o(*゚▽゚*)o)))</p>
<!-- 主打分类 -->
<p>本站主打三类文章,以下为快速通道:</p>
<nav class="MainCategories LightBox">
<ul>
{% for cat in site.categories limit: 3 %}
{% assign c = cat[0] %}
{% assign c_d = site.data.taxonomy.categories[c] %}

<li>
<a href="/categories/{{ c }}/" style="background-image: url('{{ c_d.thumbnail | asset_path }}')">
<h3 data-toc-skip="true">{{ c_d.name }}</h3>
<p>{{ c_d.description }}</p>
</a>
</li>
{% endfor %}
</ul>
</nav>
<!-- 文章列表 -->
<div class="ArticleList">
{% assign prev_post = null %}
{% assign first_post_year = posts.last.date | date: "%Y" %}
{% assign last_post_year = first_post.date | date: "%Y" %}

{% assign current_year = site.time | date: "%Y" %}
{% assign year_duration = 10 %}

<div class="ArticleList-summary">
<p><span class="u-bold">{{ last_post_year | minus: first_post_year | plus: 1 }}</span> 年间共写了 <span class="u-bold">{{ posts.size }}</span> 篇文章。本页只显示最近十年({{ current_year | minus: year_duration | plus: 1 }} 年~{{ current_year }} 年)的文章,其他年份的文章请访问下面的年份归档页面:</p>
<ul class="ArticleList-archives">
{% for post in posts %}
{% assign prev_year = prev_post.date | date: "%Y" %}
{% assign year = post.date | date: "%Y" %}
{% assign diff = current_year | minus: year %}

{% if prev_post == null or year != prev_year %}
{% assign first_item = true %}
{% else %}
{% assign first_item = false %}
{% endif %}

{% if diff >= year_duration %}
{% if first_item == true %}
{% assign year_posts = 0 %}

{% for p in site.posts %}
{% assign y = p.date | date: "%Y" %}

{% if y == year %}
{% assign year_posts = year_posts | plus: 1 %}
{% endif %}
{% endfor %}

<li class="col-xs-6 col-sm-4"><a href="/archives/{{ year }}/">{{ year }}<span><i class="fa fa-pencil"></i>共 {{ year_posts }} 篇</span></a></li>
{% else %}
{% continue %}
{% endif %}
{% endif %}

{% assign prev_post = post %}
{% endfor %}
</ul>
</div>

{% for post in posts %}
{% assign prev_year = prev_post.date | date: "%Y" %}
{% assign year = post.date | date: "%Y" %}
{% assign diff = current_year | minus: year %}

{% if prev_post == null or year != prev_year %}
{% assign first_item = true %}
{% else %}
{% assign first_item = false %}
{% endif %}

{% if diff < year_duration %}
{% if first_item == true %}
<h2 class="ArticleList-heading" title="共 {{ site.data.blog.posts.years[year] }} 篇">{{ year }}</h2>
{% endif %}

<div class="ArticleList-item"><time datetime="{{ post.date | date_to_xmlschema }}">{{ post.date | date: "%F" }}</time><i class="fa fa-pencil"></i><a href="{{ post.url }}">{{ post.title }}</a>{% if post.album %}<i class="fa fa-camera"></i>{% endif %}{% if post.tags contains 'vlog' %}<i class="fa fa-video-camera"></i>{% endif %}</div>
{% endif %}

{% assign prev_post = post %}
{% endfor %}
</div>
{% else %}
<p>暂无文章</p>
{% endif %}
19 changes: 19 additions & 0 deletions src/jekyll/_includes/ksio/pages/posts/footer.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{% if site.posts.size > 0 %}
<aside class="Widget Widget--hotCategories">
<div class="Widget-body">
{% assign categories = site.data.taxonomy.categories %}
{% assign cats = site.categories %}
{% assign cat = cats.first %}
{% assign c = cat[0] %}
<p>文章类别<a href="/categories/{{ c }}/">{{ categories[c].name }}</a>下有<span>{{ cat[1].size }}</span>篇文章,其他热门类别有</p>
<ul>
{% for cat in cats limit: 5 offset: 1 %}
{% assign c = cat[0] %}
<li><a href="/categories/{{ c }}/">{{ categories[c].name }} ({{ cat[1].size }})</a></li>
{% endfor %}
</ul>
</div>
</aside>
{% endif %}
{% include ksio/widgets/share.html %}
{% include ksio/widgets/toc.html %}
2 changes: 1 addition & 1 deletion src/jekyll/_includes/ksio/slots/aside.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% if page.ksio_slot_aside %}
<div class="Page-sidebar col-md-3">{% include "{{ page.ksio_slot_aside | replace: '.html', '' }}.html" %}</div>
<div class="Page-sidebar col-md-3">{% include {{ page.ksio_slot_aside | replace: ".html", "" | append: ".html" }} %}</div>
{% else %}
{% ifhascontent sidebar %}
<div class="Page-sidebar col-md-3">{% contentblock sidebar %}</div>
Expand Down
2 changes: 1 addition & 1 deletion src/jekyll/_includes/ksio/slots/banner.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% if page.ksio_slot_banner %}
{% include "{{ page.ksio_slot_banner | replace: '.html', '' }}.html" %}
{% include {{ page.ksio_slot_banner | replace: ".html", "" | append: ".html" }} %}
{% else %}
{% assign banner = page.banner %}
{% if banner %}
Expand Down
2 changes: 1 addition & 1 deletion src/jekyll/_includes/ksio/slots/content.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{% if page.ksio_slot_content %}{% include "{{ page.ksio_slot_content | replace: '.html', '' }}.html" %}{% else %}{{ content }}{% endif %}
{% if page.ksio_slot_content %}{% include {{ page.ksio_slot_content | replace: ".html", "" | append: ".html" }} %}{% else %}{{ content }}{% endif %}
2 changes: 1 addition & 1 deletion src/jekyll/_includes/ksio/slots/footer.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% if page.ksio_slot_footer %}
{% include "{{ page.ksio_slot_footer | replace: '.html', '' }}.html" %}
{% include {{ page.ksio_slot_footer | replace: ".html", "" | append: ".html" }} %}
{% else %}
{% ifhascontent footer %}{% contentblock footer %}{% endifhascontent %}
{% ifnothascontent footer %}
Expand Down
6 changes: 3 additions & 3 deletions src/jekyll/_includes/ksio/slots/header.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{% if page.ksio_slot_header %}
{% include "{{ page.ksio_slot_header | replace: '.html', '' }}.html" %}
{% include {{ page.ksio_slot_header | replace: ".html", "" | append: ".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>
<h1 class="Article-title">{% include {{ page.ksio_slot_title | replace: ".html", "" | append: ".html" }} %}</h1>
{% else %}
{% ifhascontent post_title %}
<h1 class="Article-title">{% contentblock post_title %}</h1>
Expand All @@ -16,7 +16,7 @@ <h1 class="Article-title">{{ page.title }}</h1>
{% endifnothascontent %}
{% endif %}
{% if page.ksio_slot_meta %}
{% include "{{ page.ksio_slot_meta | replace: '.html', '' }}.html" %}
{% include {{ page.ksio_slot_meta | replace: ".html", "" | append: ".html" }} %}
{% else %}
{% ifhascontent post_meta %}
{% contentblock post_meta %}
Expand Down
2 changes: 1 addition & 1 deletion src/jekyll/_layouts/ksio/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<html lang="zh-CN" dir="ltr" data-layout="{{ page.layout_type }}">
{% endif %}
<head>
{% include ksio/head.html %}
{% include ksio/partials/head.html %}
<!-- 静态资源 -->
{% if site.ksio.social.comment.disqus.proxy %}{% stylesheet ksio/vendors/disqusjs.min %}{% endif %}
{% stylesheet global %}
Expand Down
14 changes: 14 additions & 0 deletions src/jekyll/_layouts/ksio/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
layout: ksio/default
---

{% include {{ site.ksio.header.partial | default: "ksio/partials/header.html" }} %}
<main class="Page-content" style="height: 100%;">
<div style="height: calc(100% - 271px); display: flex; align-items: center; justify-content: center; text-align: center;">
<div>
<h1 style="margin-top: 0; margin-bottom: .3em; font-size: 10rem; font-weight: 700;">{{ site.title }}</h1>
<p style="margin-bottom: 0; font-size: 2.5rem;">{{ site.tagline | default: site.description }}</p>
</div>
</div>
</main>
{% include {{ site.ksio.footer.partial | default: "ksio/partials/footer.html" }} %}
2 changes: 1 addition & 1 deletion src/jekyll/_pages/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
permalink: 404.html
---

<p>孩子,迷路了吧?来让蜀黍<a href="{{ '/' | prepend: site.baseurl | prepend: site.url }}">送你回家</a></p>
{% include ksio/pages/404.html %}
5 changes: 0 additions & 5 deletions src/jekyll/_pages/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,3 @@ title: 关于本站
{:#donation}

若您正在使用或喜欢本主题,请考虑[请我喝杯咖啡]({{ sponsor_url }}#donation){:target="_blank"}{:rel="external "}以表心意;也许除了本主题之外,还看好[我写的文章](https://ourai.ws/posts/?{{ utm_params }}){:target="_blank"}{:rel="external "}和[其他作品](https://oss.ourai.ws/?{{ utm_params }}){:target="_blank"}{:rel="external "},希望能够保持长期且高质量的产出,也可以考虑[赞助]({{ sponsor_url }}#sponsor){:target="_blank"}{:rel="external "}我,感激不尽!

{% contentfor footer %}
{% include ksio/widgets/share.html %}
{% include ksio/widgets/toc.html %}
{% endcontentfor %}
4 changes: 2 additions & 2 deletions src/jekyll/_pages/guides.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
title: 概述
layout: ksio/doc
css:
- ksio/pages/post
- ksio/pages/doc
- local/pages/post
- local/pages/doc
js:
- ksio/initializers/time
- ksio/initializers/lazyload
Expand Down
2 changes: 1 addition & 1 deletion src/jekyll/_pages/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
permalink: index.html
---

{% include ksio/header.html %}
{% include ksio/partials/header.html %}
<main class="Page-content">
<article class="Homepage">
<header class="Homepage-header">
Expand Down

0 comments on commit 170f102

Please sign in to comment.