博客装修记录2:自定义一句话简介

即:自定义新Front-matter变量

装修 277字

自定义新Front-matter变量

  1. 直接在文章的Front-matter参数部分添加新参数newvaluable: 内容描述

  2. 用if语句检测变量是否存在,可以在对应文件中插入代码等(在对应文件中找到插入位置的方法参照装修记录1)。格式如下(参考网页):

1
2
3
4
5
6
7
<% if (post.thumbnail){ %>
<div class="post-thumbnail">
<a href="<%- url_for(post.path) %>">
<img src="<%- url_for(post.thumbnail) %>" alt="<%= post.title %>" itemprop="image">
</a>
</div>
<% } %>

 然而,当我做到这一步,我无语地发现我根本不需要自己定义一个新变量。因为我打开对应位置的代码之后发现,它早就给我写好了description。如下:

1
2
3
4
5
6
7
8
9
10
11
<% if (post.excerpt) { %>
<%- post.excerpt %>
<% } else if (post.description) { %>
<p>
<%- strip_html(post.description) %>
</p>
<% } else if (theme.meta.auto_excerpt.enable) { %>
<p>
<%- strip_html(truncate(post.content, {length: theme.meta.auto_excerpt.length})) %>
</p>
<% } %>

至少现在更加理解代码语法了,可喜可贺。