Hexo 关于博客项目结构与核心命令的笔记

文件框架解析

_config.yml文件

文件内部分为这些板块: Site, URL, Directory, Writing, Home page Setting, Category & Tag, Metadata elements, Date / Time format, Pagination(页码), Include / Exclude file(s), Extensions, Deployment

URL模块控制网址的结构和链接生成规则; Directory模块定义输入输出的路径; Writing控制写作相关体验; Category & Tag控制分类/标签的默认行为和URL映射; Pagination控制非首页的分页行为

具体细节查看源文件注释

_config.landscape.yml

控制landscape这款主题; Hexo 允许为每个主题单独建立配置文件(命名规则为 _config.[主题名].yml

package.json & package-lock.json

前者是项目依赖清单, 执行npm install的时候会根据此文件进行安装, 后者是用来确保在不同环境安装的依赖版本完全一致

source/

内容源目录。一般情况下, 内部的 _posts/ 会被渲染发布,_drafts/ 默认不渲染,其余文件/文件夹会按原样输出或根据规则渲染后发布

scaffolds/

文章/页面模板目录

themes/

主题文件目录(注:Hexo 标准目录名为复数 themes/

public/

静态文件输出目录, 使用hexo generate命令之后, hexo会将source/和themes/中的内容合并渲染并放入此处, 成为部署到服务器的内容

db.json

缓存数据库, 记录文件变动与元数据以加速生成, 可安全删除

Hexo命令解析

从终端–help得到的命令如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
INFO  Validating config
Usage: hexo <command>

Commands:
clean Remove generated files and cache.
config Get or set configurations.
deploy Deploy your website.
generate Generate static files.
help Get help on a command.
init Create a new Hexo folder.
list List the information of the site
migrate Migrate your site from other system to Hexo.
new Create a new post.
publish Moves a draft post from _drafts to _posts folder.
render Render files with renderer plugins.
server Start the server.
version Display version information.

Global Options:
--config Specify config file instead of using _config.yml
--cwd Specify the CWD
--debug Display all verbose messages in the terminal
--draft Display draft posts
--safe Disable all plugins and scripts
--silent Hide output on console

For more help, you can use 'hexo help [command]' for the detailed information
or you can check the docs: https://hexo.io/docs/

server & generate & clean

server : 启动本地服务器, 实时预览
generate : 将source/中的markdown和主题模板一起渲染为三件套文件, 输出到public/
clean : 清除public/和db.json

new & publish

new : 创建新文章/页面/草稿
publish: 将草稿内容发布

config & list

config : 用于查看或者修改_config.yml的内容
list : 列出站点信息(文章、页面、分类、标签等)

按需使用

deploy: 一键部署
render: 单独渲染指定文件
migrate: 从其它博客迁移数据
init: 初始化Hexo项目
help: 查看命令帮助
version: 显示版本信息