hexo常用命令

hexo常用命令,下面解释每个命令的具体使用方式

常见命令

1
2
3
4
5
6
7
hexo new "postName" #新建文章
hexo new page "pageName" #新建页面
hexo generate #生成静态页面至public目录
hexo server #开启预览访问端口(默认端口4000,'ctrl + c'关闭server)
hexo deploy #部署到GitHub
hexo help # 查看帮助
hexo version #查看Hexo的版本

缩写:

1
2
3
4
hexo n == hexo new
hexo g == hexo generate
hexo s == hexo server
hexo d == hexo deploy

组合命令:

1
2
hexo s -g #生成并本地预览
hexo d -g #生成并上传

init

1
$ hexo init [folder]

新建一个网站。如果没有设置 folderHexo 默认在目前的文件夹建立网站。

new

1
$ hexo new [layout] <title>

新建一篇文章。如果没有设置 layout 的话,默认使用 _config.yml 中的 default_layout 参数代替。如果标题包含空格的话,请使用引号括起来。

1
$ hexo new "post title with whitespace"

generate

1
$ hexo generate

生成静态文件。

选项描述
-d, --deploy文件生成后立即部署网站
-w, --watch监视文件变动

该命令可以简写为

1
$ hexo g

publish

1
$ hexo publish [layout] <filename>

发表草稿。

server

1
$ hexo server

启动服务器。默认情况下,访问网址为: http://localhost:4000/

选项描述
-p, --port重设端口
-s, --static只使用静态文件
-l, --log启动日记记录,使用覆盖记录格式

deploy

1
$ hexo deploy

部署网站。

参数描述
-g, --generate部署之前预先生成静态文件

该命令可以简写为:

1
$ hexo d

render

1
$ hexo render <file1> [file2] ...

渲染文件。

参数描述
-o, --output设置输出路径

migrate

1
$ hexo migrate <type>

从其他博客系统 迁移内容

clean

1
$ hexo clean

清除缓存文件 (db.json) 和已生成的静态文件 (public)。

在某些情况(尤其是更换主题后),如果发现您对站点的更改无论如何也不生效,您可能需要运行该命令。

list

1
$ hexo list <type>

列出网站资料。

version

1
$ hexo version

显示 Hexo 版本。

选项

安全模式

1
$ hexo --safe

在安全模式下,不会载入插件和脚本。当您在安装新插件遭遇问题时,可以尝试以安全模式重新执行。

调试模式

1
$ hexo --debug

在终端中显示调试信息并记录到 debug.log。当您碰到问题时,可以尝试用调试模式重新执行一次,并 提交调试信息到 GitHub

简洁模式

1
$ hexo --silent

隐藏终端信息。

自定义配置文件的路径

1
$ hexo --config custom.yml

自定义配置文件的路径,执行后将不再使用 _config.yml

显示草稿

1
$ hexo --draft

显示 source/_drafts 文件夹中的草稿文章。

自定义 CWD

1
$ hexo --cwd /path/to/cwd

自定义当前工作目录(Current working directory)的路径。

模板

如本站所示,用的是The-Next模板,不知何时起发现网站没有keywords了,查排名都没有关键词,keywords,那要如何加呢?

其实这点可以参考文章里如何取tags的,循环下加到keywrods里就行了。

有两个地方可以加:

layout/_partials/head/head.njklayout/_layout.njk,这两个都是公用文件,我直接上代码吧:

1
2
3
4
5
6
7
8
{%- if is_post() or is_page() %}
{%- if page.tags and page.tags.length %}
<meta name="keywords" content="{%- for tag in page.tags.toArray() %}{{ tag.name }},{%- endfor %}">
{%- endif %}
{%- else %}
<meta name="keywords" content="{{ config.keywords }}">
<meta name="description" content="{{ config.descriptions }}">
{%- endif %}

大概意思就是,如果是文章页或page页面,我就去tag循环拿到keywords,因为文章里默认提取了description,所以文章里就没有再取。首页和其他页面是取的配置文件里的两个参数,重新生成下即可。

文章内容增加阴影

进入主题文件夹:hexo-theme-next\source\css\_common\components\post\post-body.styl

进入.post-body下的img{},增加对应的border-radius和box-shadow即可:

1
2
3
4
5
iframe, img, video, embed {
margin-bottom: 20px;
border-radius: 5px;
box-shadow: 0 10px 30px 0 rgb(0 0 0 / 40%);
}