LoginSignup
1
1

More than 5 years have passed since last update.

【Github Pages】Hexo搭建Github静态博客

Posted at

1. 通过Homebrew安装Node.js和npm

$ brew install node

$ node -v
v4.2.0

2. 安装Hexo

$ npm install -g hexo

$ hexo -v
hexo-cli: 0.1.9
os: Darwin 14.5.0 darwin x64
http_parser: 2.5.0
node: 4.2.0
v8: 4.5.103.35
uv: 1.7.5
zlib: 1.2.8
ares: 1.10.1-DEV
icu: 56.1
modules: 46
openssl: 1.0.2d

3. 建立项目

$ hexo init blog
INFO  Copying data to ~/Documents/blog
INFO  You are almost done! Don't forget to run 'npm install' before you start blogging with Hexo!

按照提示,运行 npm instal

cd blog
npm install

4. 运行服务器

hexo server

5. 设置主题

本文以设置NexT为例
https://github.com/iissnan/hexo-theme-next

$ cd blog
$ git clone https://github.com/iissnan/hexo-theme-next themes/next

将_config.yml配置文件中的theme属性设置为next

theme: next

6. 安装插件

  • sitemap插件
$ npm install hexo-generator-sitemap
# Extensions
Plugins:
- hexo-generator-sitemap

#sitemap
sitemap:
  path: sitemap.xml
  • feed插件
$ npm install hexo-generator-feed
# Extensions
Plugins:
- hexo-generator-feed
- hexo-generator-sitemap

#Feed Atom
feed:
  type: atom
  path: atom.xml
  limit: 20

7. 部署到GitHub Pages

npm install hexo-deployer-git --save

编辑_config.yml中development的部分

# Deployment
## Docs: http://hexo.io/docs/deployment.html
deploy:
  type: github
  repo: git@github.com:xxxx/xxxx.github.io.git
  branch: master

本地测试:

hexo s -g

部署:

hexo d -g

# hexo generate -deploy

# hexo clean
# hexo generate
# hexo deploy

常用命令

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

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1