配置 SSH KEY
cd ~/.ssh
rm *
ssh-keygen -t rsa -C mail_address
连按回车 3 次,得到 id_rsa 和 id_rsa.pub 文件,将后者复制到 GitHub New SSH key。测试是否成功(输入 yes,看到 successful 即可):
ssh -T git@github.com
再配置:
git config --global user.name "name"
git config --global user.email "mail_address"
安装 Homebrew
将下面代码粘贴在 Terminal 中:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Homebrew 会将套件安装到独立目录,并将文件软链接至 /usr/local。基本语法如下:
brew install wget
brew uninstall wget
brew list
brew update
brew home
brew info
brew deps
清理旧版本(可选)
删除 hexo:
npm uninstall hexo-cli -g
npm uninstall hexo -g # 之前版本执行
删除 node:
brew remove --force node
sudo rm -rf /usr/local/lib/node_modules/
brew prune
sudo rm -r /usr/local/include/node
brew doctor
安装 Node.js
brew install node
使用 node -v 检查 Node 版本。npm (node package manager) 在 Node.js 安装的时候顺带装好了,使用 npm -v 检查 npm 版本。
安装 Hexo
npm install -g hexo-cli
npm install hexo-deployer-git --save
初始化框架
hexo init blog
cd blog
npm install
hexo 基本语法如下:
hexo s
hexo clean
hexo d -g
初始化博客
hexo init blog
cd blog
npm install
hexo server
在浏览器中输入 http://localhost:4000/ 预览效果。
发布文章
hexo new [layout] <title>
其中 layout 包括 post、page、draft 三类。草稿发布用:
hexo publish [layout] <title>
安装 NEXT 主题
利用 git 下载 next 主题:
cd blog
git clone https://github.com/iissnan/hexo-theme-next themes/next
配置站点 _config.yml 文件:
# Site
title: hcgu blog
subtitle:
description:
author: hcgu
language: en
timezone: Asia/Shanghai
...
url: http://gulab.cn
...
theme: next
...
deploy:
type: git
repo: git@github.com:name/name.github.io.git
branch: master
配置主题 _config.yml 文件:
scheme: Mist
...
# MathJax Support
mathjax:
enable: true
使用 TAGS 和 CATEGORIES
使用 hexo new page tags 在站点生成 tags 文件夹,编辑 source/tags/index.md 如下:
title: tags
date: 2017-06-08 16:49:50
type: "tags"
comments: false
类似的,使用 hexo new page categories 在站点生成 categories 文件夹,编辑 source/categories/index.md 如下:
title: categories
date: 2017-06-08 16:49:55
type: "categories"
comments: false
发布文章时,在头部添加 tags: [tag1,tag2,tag3] 或 categories: "cate1" 进行使用。
使用本地图片
在站点 _config.yml 中确认:
post_asset_folder: true
切换至站点目录,执行:
npm install https://github.com/CodeFalling/hexo-asset-image --save
安装成功后,使用 hexo new "new_post" 新建文章时,将产生 new_post.md 和 new_post 文件夹。将图片保存在 new_post 文件夹,然后通过  来插入图片。
自定义域名
先注册域名 gulab.cn,然后在站点 source 目录下添加 CNAME:
gulab.cn
使用 dnspod 进行域名解析,添加域名 gulab.cn 后,自动从域名服务商导入记录。在域名服务商后台修改 NS 记录如下:
f1g1ns1.dnspod.net
f1g1ns2.dnspod.net
访问博客
地址为 gulab.cn。
添加 RSS
npm install hexo-generator-feed --save