Permalink
Browse files

feat: post.description/excerpt 首页文章摘要

Add a setting “description” in Front-matter,
it have a higher-priority than <!-- more —>.

通过文章 front-matter 中设置 description,可以自定义首页文章摘要,与 Next 主题类似。
  • Loading branch information...
MOxFIVE committed Dec 2, 2015
1 parent 56abe42 commit 2083b8a63e43c8d682e86ce788790ba93f96fc05
Showing with 47 additions and 12 deletions.
  1. +31 −0 README.md
  2. +16 −12 layout/_partial/article.ejs
View
@@ -52,6 +52,37 @@ git pull
### Configuration 配置
#### 0. Post Excerpt 文章摘要
There are two ways to show excerpt in homepage.
目前主题可使用两种方式在首页显示文章摘要而不是全文。
- a: <!-- more -->
``` diff
title: Hello World
date: 2015-12-03 00:00:00
---
<Excerpt in index | 首页摘要>
+ <!-- more -->
<The rest of contents | 余下全文>
```
- b: description in Front-matter
``` diff
title: Hello World
date: 2015-12-03 00:00:00
+ description: "Welcome to Hexo! This is your very first post."
---
<Contents>
```
> Description only support plain text. | 通过 description 添加的摘要只能为纯文本。
> Set the value of description with quotes to avoid unexpected error `:`. | description 的内容加双引号,可以避免一些程序错误,例如内容里包含英文冒号时。
#### 1. About Page 关于我页面:
cd to your hexo folder and run this code:
@@ -21,12 +21,16 @@
<% } %>
<% } %>
<div class="article-entry" itemprop="articleBody">
<% if (post.excerpt && index){ %>
<%- post.excerpt %>
<% if (index && (post.description || post.excerpt)){ %>
<% if (post.description){ %>
<%- post.description %>
<% } else { %>
<%- post.excerpt %>
<% } %>
<% } else { %>
<% if (is_page()){ %>
<%- partial('_partial/page') %>
<% } %>
<% if (is_page()){ %>
<%- partial('_partial/page') %>
<% } %>
<%- post.content %>
<% } %>
</div>
@@ -39,7 +43,7 @@
<% } %>
<%- partial('post/category') %>
<%- partial('post/tag') %>
<% if (post.excerpt && index){ %>
<% if (index && (post.description || post.excerpt)){ %>
<p class="article-more-link">
<a <% if (!theme.excerpt_link){ %>class="hidden"<% } %> href="<%- url_for(post.path) %>#more"><%= theme.excerpt_link %> >></a>
</p>
@@ -60,11 +64,11 @@
<% } %>
<% if (!index && theme.duoshuo && post.comments){ %>
<%- partial('post/duoshuo', {
key: post.path,
title: post.title,
url: config.url+url_for(post.path)
}) %>
<%- partial('post/duoshuo', {
key: post.path,
title: post.title,
url: config.url+url_for(post.path)
}) %>
<% } %>
<% if (!index && post.comments && config.disqus_shortname){ %>
@@ -115,7 +119,7 @@
open_in_new: <%=theme.open_in_new%>
}
</script>
<% } %>
<% } %>
<% } else { %>
<script>
var yiliaConfig = {

0 comments on commit 2083b8a

Please sign in to comment.