抽离出页面模板 page.ejs,根据不同的路由,渲染不同内容

This commit is contained in:
XPoet 2020-03-15 17:39:18 +08:00
parent 7dabe2e538
commit c932dd1258
6 changed files with 30 additions and 23 deletions

View File

@ -1,14 +1 @@
<!-- 检查当前页面是否为存档页面 --> <%- partial('page') %>
<h1> 存档页面 </h1>
<% if (is_archive()) { %>
<ul class="post-container">
<% page.posts.forEach(post => { %>
<li class="post-item">
<div> 文章标题:<%= post.title %> </div>
<div> 建立日期:<%= date(post.date, 'YYYY-MM-DD HH:MM:SS') %> </div>
<div> 更新日期:<%= date(post.updated, 'YYYY-MM-DD HH:MM:SS') %> </div>
<div> 页面摘要:<%= post.excerpt ? post.excerpt : '页面无摘要' %> </div>
</li>
<% }) %>
</ul>
<% } %>

View File

@ -0,0 +1,11 @@
<!-- 归档页面 内容 -->
<ul class="archive-post-container">
<% site.posts.forEach(post => { %>
<li class="post-item">
<div> 文章标题:<%= post.title %> </div>
<div> 建立日期:<%= date(post.date, 'YYYY-MM-DD HH:MM:SS') %> </div>
<div> 更新日期:<%= date(post.updated, 'YYYY-MM-DD HH:MM:SS') %> </div>
<div> 页面摘要:<%= post.excerpt ? post.excerpt : '页面无摘要' %> </div>
</li>
<% }) %>
</ul>

View File

@ -50,6 +50,7 @@
<% } %> <% } %>
<!-- 分页器 --> <!-- 分页器 -->
<!-- https://hexo.io/zh-cn/docs/helpers#paginator -->
<div class="paginator"> <div class="paginator">
<!--<ul class="paginator-btn-box"> <!--<ul class="paginator-btn-box">

View File

@ -1,9 +1,2 @@
<!-- index 首页 --> <!-- index 首页 -->
<div class="page-container"> <%- partial('page') %>
<div class="page-left">
<%- partial('left-side') %>
</div>
<div class="page-right">
<%- partial('right-side') %>
</div>
</div>

9
layout/page.ejs Normal file
View File

@ -0,0 +1,9 @@
<!-- 页面模板 -->
<div class="page-container">
<div class="page-left">
<%- partial('left-side') %>
</div>
<div class="page-right">
<%- partial('right-side') %>
</div>
</div>

View File

@ -3,6 +3,12 @@
<%- partial('common/nav') %> <%- partial('common/nav') %>
</div> </div>
<div class="article-post-container"> <div class="article-post-container">
<%- partial('common/article-post') %> <% if (is_archive()) { %>
<!-- 载入归档页内容 -->
<%- partial('common/archive-post') %>
<% } else { %>
<!-- 载入首页内容 -->
<%- partial('common/article-post') %>
<% } %>
</div> </div>
</div> </div>