[部署]hexo博客 & Github Pages部署记录

2.6k words

1.Windows环境配置

  • Git https://git-scm.com/

  • Node https://nodejs.org/en

  • Pandoc https://pandoc.org/

2.安装Hexo

1
2
3
4
5
6
7
8
9
10
npm config set registry https://registry.npmmirror.com

npm install -g hexo-cli

npm install --save hexo-deployer-git

# 本地测试
hexo init # 初始化博客
hexo generate # 申城网站信息
hexo server # 开始网站服务

3.Github仓库

在你的github中新建仓库“username.github.io”,其中,username就是你注册时使用的用户名。

修改你博客根目录下的_config.yml文件中的deploy配置项:

1
2
3
4
deploy:
type: git
repository: git@github.com:username/username.github.io.git # 你的仓库地址
branch: gh-pages

他会在你的仓库的gh-pages分支部署你的页面,然后再master分支保存你网站的源代码,不会相互覆盖。

通过如下代码进行部署:

1
2
3
4
5
6
7
8
9
10
11
12
hexo clean # 清除缓存
hexo generate # 生成网站
hexo deploy # 部署至远程网络

# 简写
hexo cl
hexo g
hexo d

# 简简写
hexo cl
hexo g -d # hexo d -g

然后就可以在浏览器上输入http://username.github.io访问你的博客了。

4.Github保存源码

1
2
3
4
5
6
7
8
9
10
11
git init

git add .

git commit -m '...'

git remote add origin git@github.com:oixel64/oixel64.github.io.git

git pull --rebase git@github.com:oixel64/oixel64.github.io.git master

git push

设置.gitignore

1
2
3
4
5
6
7
8
9
.DS_Store
Thumbs.db
db.json
*.log
node_modules/
public/
.deploy*/
_multiconfig.yml
public/

再上GitHub设置master为主分支,删除main分支,以gh-pages分支部署Github Pages

5.主题

https://github.com/saicaca/hexo-theme-vivia

1
2
3
4
5
6
7
npm install hexo-theme-vivia

mv node_modules/hexo-theme-vivia/example_zh_CN_config.vivia.yml _config.vivia.yml

hexo config theme vivia

hexo new page about

编辑_config.yml 添加:

1
2
archive_generator:
per_page: 0

6.LaTex公式

https://github.com/next-theme/hexo-filter-mathjax

https://github.com/hexojs/hexo-renderer-pandoc

1
2
3
npm install hexo-filter-mathjax

hexo clean

配置_config.yml:

1
2
3
4
5
6
7
8
9
10
11
mathjax:
tags: none # or 'ams' or 'all'
single_dollars: true # enable single dollar signs as in-line math delimiters
cjk_width: 0.9 # relative CJK char width
normal_width: 0.6 # relative normal (monospace) width
append_css: true # add CSS to pages rendered by MathJax
every_page: true # if true, every page will be rendered by MathJax regardless the `mathjax` setting in Front-matter
packages: # extra packages to load
extension_options: {}
# you can put your extension options here
# see http://docs.mathjax.org/en/latest/options/input/tex.html#tex-extension-options for more detail

本地电脑安装配置Pandoc后:

1
2
3
npm uninstall hexo-renderer-marked

npm install hexo-renderer-pandoc --save

7.图床

不重复造轮子,这篇知乎写得非常好了:

https://zhuanlan.zhihu.com/p/112912928

8.写作

1
2
3
4
5
6
7
8
9
10
11
hexo new "[部署]hexo博客 & Github Pages部署记录"

hexo cl

hexo g -d

git add .

git commit -m '...'

git push

新电脑写作

基本工作nodejs+git+pandoc,GitHub仓库上添加ssh公钥,在新电脑执行:

1
2
3
ssh-keygen -t rsa

cat C:\Users\Feng\.ssh\id_rsa.pub

克隆项目:

1
2
3
4
5
6
7
8
9
10
11
git clone git@github.com:oixel64/oixel64.github.io.git

cd .\oixel64.github.io\

npm config set registry https://registry.npmmirror.com

npm install -g hexo-cli

npm install --save hexo-deployer-git

npm install

若npm install失败,管理员开启powershell

1
2
3
set-ExecutionPolicy RemoteSigned

N

验证:

1
hexo -V

重复 写作 部分