准备工作
- 安装Git. 将本地的网页和文章等内容发布或提交到GitHub上需要用到Git.
- 安装Node.js. Hexo是基于Node.js的高效静态站点生成框架.
- 安装Hexo. 在Node.js安装完成后, 通过控制台执行以下命令即可.
npm install hexo-cli -g
创建博客
hexo init leiz2192.hexo
cd leiz2192.hexo
hexo new "YourBlogTitle" //会生成source/_posts/YourBlogTitle.md
然后撰写YourBlogTitle.md.
hexo g //生成网页
hexo s //s是server的缩写,启动服务, 通过http://localhost:4000/本地访问
发布博客
安装部署插件
npm install hexo-deployer-git --save
创建部署仓库
在GitHub上”Create a new repository”, Repository name为your-github-user-name.github.io, 比如leiz2192.github.io
配置部署参数
在_config.yml中配置deploy.
deploy:
type: git
repo: git@github.com:leiz2192/leiz2192.github.io.git
branch: master
repo建议使用ssh方式地址, https方式在部署时会需要输入用户名和密码.
生成发布博客
hexo d -g //生成网页并发布到GitHub
然后就可以访问博客.
维护博客
博客的网页在repo leiz2192.github.io中维护, 而博客的md文件可以在repo leiz2192.hexo中维护. 这样数据和网页分离, 便于管理.
而在电脑或系统改变了, git clone leiz2192.hexo后就可以继续维护博客, 而且历史文章不丢失.
另外, 利用git hook可以在每次git push时自动发布博客, 只需在.git/hooks目录中新增pre-push文件, 文件内容如下.
#!/bin/sh
hexo d -g
exit 0
修饰博客
about
新建about page
hexo new page "about"
修改theme的_config.yml
, 去注释menu
中的about
.
menu:
......
about: /about/ || user
然后修改source/about/index.md
文件即可.
tags
新建tags page
hexo new page "tags"
修改theme的_config.yml
, 去注释menu
中的tags
.
menu:
......
tags: /tags/ || tags
然后修改source/tags/index.md
文件, 增加type: "tags"
---
title: tags
date: 2019-10-04 23:11:52
type: "tags"
---
categories
新建categories page
hexo new page "categories"
修改theme的_config.yml
, 去注释menu
中的categories
.
menu:
......
categories: /categories/ || th
然后修改source/categories/index.md
文件, 增加type: "categories"
---
title: categories
date: 2019-10-04 23:15:38
type: "categories"
---
search
安装插件
npm install hexo-generator-searchdb --save
修改站点的配置文件_config.yml
, 增加以下内容.
search:
path: search.xml
field: post
format: html
limit: 10000
修改theme的_config.yml
, 修改local_search
的enable
为true.
local_search:
enable: true
清理缓存后发布.
hexo clean
hexo d -g