Skip to content

Commit

Permalink
feat(hexo): post list page
Browse files Browse the repository at this point in the history
  • Loading branch information
ourai committed Apr 7, 2023
1 parent a57263b commit b88d662
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/hexo/source/posts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: 博客
ksio_slot_banner: _ksio/pages/posts/banner
ksio_slot_content: _ksio/pages/posts/content
ksio_slot_footer: _ksio/pages/posts/footer
ksio_asset_css:
- stylesheets/pages/posts
---
7 changes: 7 additions & 0 deletions src/hexo/themes/lime/layout/_ksio/pages/posts/banner.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<% const banner_url = url_for('images/ksio/banners/blog.jpg') %>
<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>
37 changes: 37 additions & 0 deletions src/hexo/themes/lime/layout/_ksio/pages/posts/content.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<% const posts = site.posts.data || site.posts %>
<% if (posts.length > 0) { %>
<% const first_post = posts[0] %>
<% const author = first_post.author || config.author %>
<!-- 最新文章 -->
<p>最近的一篇文章发表于 <time datetime="<%= date_xml(first_post.date) %>" class="u-bold"><%= date(first_post.date, 'YYYY 年 M 月 D 日') %></time>——</p>
<blockquote>
<p><%= truncate(escape_html(trim(strip_html(markdown(first_post.content)))), 100) %></p>
<footer><%= author.name || author %></footer>
</blockquote>
<p>想看完整内容?快戳《<a href="<%= config.root || '/' %><%= first_post.path %>"><%= first_post.title %></a>》!(((o(*゚▽゚*)o)))</p>
<% if (site.categories.length > 0) { %>
<!-- 主打分类 -->
<p>本站主打三类文章,以下为快速通道:</p>
<nav class="MainCategories LightBox">
<ul></ul>
</nav>
<% } %>
<!-- 文章列表 -->
<div class="ArticleList">
<% const current_year = date(Date.now(), 'YYYY') %>
<% const year_duration = 10 %>
<% let prev_post = null %>
<% posts.forEach(post => { %>
<% const prev_year = prev_post ? date(prev_post.date, 'YYYY') : '' %>
<% const year = date(post.date, 'YYYY') %>
<% if (current_year - year < year_duration) { %>
<% if (prev_post === null || year !== prev_year) { %>
<h2 class="ArticleList-heading"><%= year %></h2>
<% } %>
<div class="ArticleList-item"><time datetime="<%= date_xml(post.date) %>"><%= date(post.date, 'YYYY-MM-DD') %></time><i class="fa fa-pencil"></i><a href="<%= config.root || '/' %><%= post.path %>"><%= post.title %></a></div>
<% } %>
<% }) %>
</div>
<% } else {%>
<p>暂无文章</p>
<% } %>
11 changes: 11 additions & 0 deletions src/hexo/themes/lime/layout/_ksio/pages/posts/footer.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<% if (site.posts.length > 0 && site.categories.length > 0) { %>
<aside class="Widget Widget--hotCategories">
<div class="Widget-body">
<p>文章类别<a href="/categories/{{ c }}/">{{ categories[c].name }}</a>下有<span>{{ cat[1].size }}</span>篇文章,其他热门类别有</p>
<ul>
</ul>
</div>
</aside>
<% } %>
<%- partial('_ksio/widgets/share') %>
<%- partial('_ksio/widgets/toc') %>
6 changes: 6 additions & 0 deletions src/hexo/themes/lime/scripts/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ function resolvePageConfig(page, defaults) {
}
});

['ksio_asset_css', 'ksio_asset_js'].forEach(k => {
if (Array.isArray(page[k]) && page[k].length > 0) {
resolved[k] = page[k];
}
});

return mergeValues(resolveValuesFromLayout(resolved.layout || page.layout, layoutDefaults), resolved);
}

Expand Down
1 change: 1 addition & 0 deletions src/hexo/themes/lime/source/stylesheets/pages/posts.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "../ksio/pages/posts";

0 comments on commit b88d662

Please sign in to comment.