近日在移植一款 Typexho 主题到 Hexo。
变量
官方文档有介绍,但还不如自己在 vscode 调试终端看。
方法:
Ctrl + ` 打开终端,点击右上角 + 旁向下的箭头,选择 JavaScript 调试终端。
然后在主题 scripts 下的找个合适的 JS 文件打个断点。不知为什么 EJS 文件打不了断点。
辅助函数
Hexo 有许多辅助函数,条件标签和字符串处理就很好用。
模板文件
布局(Layout)
<!doctype html>
<html>
<body>
<%- body %>
</body>
</html>
<%- body %>的作用似乎是在不同的页面插入模板。
<%- body %>
<%- partial("index") %>
| 模板 | 页面 | 回退 |
|---|---|---|
index | 首页 | |
post | 文章 | index |
page | 分页 | index |
archive | 归档 | index |
category | 分类归档 | archive |
tag | 标签归档 | archive |
index
网站首页的文章列表
可以用下列代码循环输出分页文章列表
<% page.posts.each(function (post) { %>
<a href="<%= post.permalink %>" title="<%= post.title %>">
<%= post.title %>
</a>
<% }) %>
archive
归档页面
可以用下列代码循环输出所有文章列表
<% site.posts.sort('date', -1).each(function(post) { %>
<a href="<%= post.permalink %>" title="<%= post.title %>">
<%= post.title %>
</a>
<% }) %>
喜欢的话,留下你的评论吧~