要创建新帖子或新页面,你可以运行以下命令:
¥To create a new post or a new page, you can run the following command:
$ hexo new [layout] <title> |
post
是默认的 layout
,但你可以提供自己的。你可以通过编辑 _config.yml
中的 default_layout
设置来更改默认布局。
¥post
is the default layout
, but you can supply your own. You can change the default layout by editing the default_layout
setting in _config.yml
.
布局
¥Layout
Hexo 中有三种默认布局:post
、page
和 draft
。它们各自创建的文件都保存到不同的路径。新创建的帖子将保存到 source/_posts
文件夹。
¥There are three default layouts in Hexo: post
, page
and draft
. Files created by each of them is saved to a different path. Newly created posts are saved to the source/_posts
folder.
布局 | 路径 |
---|---|
post |
source/_posts |
page |
source |
draft |
source/_drafts |
Disabling layout如果你不希望文章(帖子/页面)使用主题进行处理,请在其 front-matter 中设置
layout: false
。更多细节请参考 此部分。¥If you don’t want an article (post/page) to be processed with a theme, set
layout: false
in its front-matter. Refer to this section for more details.
文件名
¥Filename
默认情况下,Hexo 使用帖子标题作为文件名。你可以在 _config.yml
中编辑 new_post_name
设置以更改默认文件名。例如,:year-:month-:day-:title.md
会在文件名前加上帖子创建日期。你可以使用以下占位符:
¥By default, Hexo uses the post title as its filename. You can edit the new_post_name
setting in _config.yml
to change the default filename. For example, :year-:month-:day-:title.md
will prefix filenames with the post creation date. You can use the following placeholders:
占位符 | 描述 |
---|---|
:title |
帖子标题(小写,空格用连字符代替) |
:year |
创建年份,例如 2015 |
:month |
创建月份(前导零),例如 04 |
:i_month |
创建月份(无前导零),例如 4 |
:day |
创建日期(前导零),例如 07 |
:i_day |
创建日期(无前导零),例如 7 |
草稿
¥Drafts
之前我们提到过 Hexo 中的一个特殊布局:draft
。使用此布局初始化的帖子将保存到 source/_drafts
文件夹。你可以使用 publish
命令将草稿移动到 source/_posts
文件夹。publish
的工作方式与 new
命令类似。
¥Previously, we mentioned a special layout in Hexo: draft
. Posts initialized with this layout are saved to the source/_drafts
folder. You can use the publish
command to move drafts to the source/_posts
folder. publish
works in a similar way to the new
command.
$ hexo publish [layout] <title> |
默认情况下不显示草稿。你可以在运行 Hexo 时添加 --draft
选项,或者在 _config.yml
中启用 render_drafts
设置来渲染草稿。
¥Drafts are not displayed by default. You can add the --draft
option when running Hexo or enable the render_drafts
setting in _config.yml
to render drafts.
脚手架
¥Scaffolds
创建帖子时,Hexo 会根据 scaffolds
文件夹中的相应文件构建文件。例如:
¥When creating posts, Hexo will build files based on the corresponding file in scaffolds
folder. For example:
$ hexo new photo "My Gallery" |
当你运行此命令时,Hexo 将尝试在 scaffolds
文件夹中找到 photo.md
并基于它构建帖子。脚手架中可用的占位符如下:
¥When you run this command, Hexo will try to find photo.md
in the scaffolds
folder and build the post based on it. The following placeholders are available in scaffolds:
占位符 | 描述 |
---|---|
layout |
布局 |
title |
标题 |
date |
文件创建日期 |
支持的格式
¥Supported Formats
Hexo 支持以任何格式编写的帖子,只要安装了相应的渲染器插件。
¥Hexo supports posts written in any format, as long as the corresponding renderer plugin is installed.
例如,Hexo 默认安装了 hexo-renderer-marked
和 hexo-renderer-ejs
,因此你可以在 markdown
或 ejs
中撰写帖子。如果你安装了 hexo-renderer-pug
,那么你甚至可以用 pug 模板语言编写你的帖子。
¥For example, Hexo has hexo-renderer-marked
and hexo-renderer-ejs
installed by default, so you can write your posts in markdown
or in ejs
. If you have hexo-renderer-pug
installed, then you can even write your post in pug template language.
你可以重命名你的帖子并将文件扩展名从 .md
更改为 .ejs
,然后 Hexo 将使用 hexo-renderer-ejs
来渲染该文件,其他格式也是如此。
¥You can rename your posts and change the file extension from .md
to .ejs
, then Hexo will use hexo-renderer-ejs
to render that file, and so do the other formats.