明道学苑

学而不思则罔,思而不学则殆

0%

Hexo新建文章时直接将页面放到子目录下

本文说明使用Hexo生成静态网站时,如果使用hexo n 指令直接将新创建的文章放到source/_post目录的子目录下

在使用Hexo生成静态站点时,为了文章管理方便,会在source/_post目录下建立子目录,对文章进行分类。

这时候,有时候就希望使用hexo n指令时直接将文章创建到子目录下面。

hexo 指令给出的提示如下:

Usage: hexo new [layout] <title>

Description:
Create a new post.

Arguments:
layout Post layout. Use post, page, draft or whatever you want.
title Post title. Wrap it with quotations to escape.

Options:
-p, --path Post path. Customize the path of the post.
-r, --replace Replace the current post if existed.
-s, --slug Post slug. Customize the URL of the post.

经过一方摸索,最后发现下面的命令可以达到目的:

hexo n -p post dir/post1

通过这个指令会在source/_post/dir目录下创建post1.md

在子目录下创建page有点不一样,需要使用下面的命令:

hexo n -p page dir/page1 "Page Example"

通过这个指令会在source/_post/dir目录下创建标题为Page Examplepage1.md

如果使用下面的命令:

hexo n -p page dir/page1

会在source/_post/dir目录下文件名是page1.md的post,因为命令行中的page会被认为是layout的参数值。