写作

首先我们可以通过执行一些命令来创建一篇新文章或者是新的页面

bun run hexo new [layout] <title>

如果hexo-cli被全局安装,那么可以直接使用

hexo new [layout] <title>

布局(Layout)

Hexo 有三种默认布局:postpagedraft。在创建文件的时候会将对应的布局放在设置好的路径中,例如新创建的post会被放到source/_posts这个文件夹里面。

布局 路径
post source/_posts
page source
draft source/_drafts

如果你不希望一篇文章(post/page)使用主题处理,请在它的front-matter中设置layout: false。这个禁用布局的功能基本用不到。

文件名称

默认情况下,hexo会使用文件标题作为其文件名。编辑设置可以更改默认文件名的格式。例如说,在文件名前加上创建后日期。可以使用:year-:month-:day-:title.md

可以使用的占位符如下:

占 位 符 描述
:title 标题(小写,空格将会被替换为短杠)
:year 建立的年份,比如, 2015
:month 建立的月份(有前导零),比如, 04
:i_month 建立的月份(无前导零),比如, 4
:day 建立的日期(有前导零),比如, 07
:i_day 建立的日期(无前导零),比如, 7

草稿

这里是一个特殊的布局:draft。使用此布局初始化的文章将保存到这个文件夹中source/_drafts。可以使用publish命令将草稿移动到source/_posts文件夹里。

bun run hexo publish [layout] <title>

默认的情况下不显示草稿。在运行时添加--draft选项或者在render_drafts中启用设置都可以渲染草稿。

Scaffolds支架

也叫脚手架,意思是在创建文章时,hexo根据scaffolds文件夹中的相应文件夹构建文件。

bun run hexo new phpto "My Gallery"

在运行命令时,hexo尝试在scaffolds文件夹中寻找到photo.md并基于它构建帖子。这个功能非常有用,尤其是想要在文章中添加一些默认的内容时。以下占位符是可用的:

Placeholder占位符 Description描述
layout Layout布局
title Title标题
date File created date文件创建日期

但是默认这三个占位符都是使用的。我会添加一些想要的front-matter, 为文章打上tags,进行分类,添加封面或摘要。

Supported Formats支持的格式

hexo支持以任何格式编写的文章,只要按照对应的渲染器。

例如,Hexo默认安装了hexo-renderer-markedhexo-renderer-ejs,所以你可以在markdownejs中写文章。如果你安装了hexo-renderer-pug,那么你甚至可以用pug模板语言写文章。

Front-matter

Front-matter是位于文件开头的yaml或者是json块,用于为写作配置设置。

这个设置有一些可选项目和默认值

Setting设置 Description描述 Default默认
layout Layout布局 config.default_layout
title Title标题 Filename (posts only)文件(仅员额)
date Published date发布日期 File created date文件创建日期
updated Updated date更新日期 File updated date文件更新日期
comments Enables comment feature for the post为帖子启用评论功能 true
tags Tags (Not available for pages)标签(不适用于页面)
categories Categories (Not available for pages)类别(不适用于页面)
permalink Overrides the default permalink of the post. Permalink should end with / or .html 覆盖文章的默认永久链接。Permalink应该以/.html结尾 null
excerpt Page excerpt in plain text. Use this plugin to format the text 纯文本中的页面摘录。使用此插件格式化文本
disableNunjucks Disable rendering of Nunjucks tag {{ }}/{% %} and tag plugins when enabled 启用时禁用Nunjucks标签{{ }}/{% %}标签插件的渲染 false假
lang Set the language to override auto-detection 设置语言以覆盖自动检测 Inherited from _config.yml 继承自_config.yml
published Whether the post should be published是否应该发布该帖子 For posts under _posts, it is true, and for posts under _draft, it is false _posts下的帖子为true_draft下的帖子为false