使用hexo搭建博客[hexo][github.io]

1 github初始化仓库

初始化git repo: 地址如下
https://github.com/xychen5/xychen5.github.io.git

2 安装相关依赖

npm install -g hexo
hexo init blogs
cd blogs
npm install -s hexo-theme-next # 安装主题
npm install --save hexo-deployer-git # 安装专用git工具
hexo s # 本地测试一下是否能正常运行

3 部署

编辑blogs/_config.yml的末尾如下:

# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: next

# Deployment
## Docs: https://hexo.io/docs/one-command-deployment
deploy:
  type: git
  repo: https://github.com/xychen5/xychen5.github.io.git
  branch: main

部署如下:

hexo clean && hexo g -d
cp .\node_modules\hexo-theme-next\_config.yml ./_config.next.yml # 将next的配置放到项目根目录,避免编辑第三方库里的yml

4 博客写作分类以及标签以及使用技巧

  • 1 https://linlif.github.io/2017/05/27/Hexo%E4%BD%BF%E7%94%A8%E6%94%BB%E7%95%A5-%E6%B7%BB%E5%8A%A0%E5%88%86%E7%B1%BB%E5%8F%8A%E6%A0%87%E7%AD%BE/
  • 2 官方guide: https://hexo.io/docs/writing

5 将hexo生成的网站(会推到xychen5.github.io库里)和自己写的markdown文件分开

  • 1 主要是将blogs/source目录下的文件用另一个库存好即可,可以使用如下步骤:
cd source
git init
git remote add origin <你的空repo地址>
git add .
git commit -m 'init'
git push -u origin master
  • 2 然后在blogs/package.json加入:
  "scripts": {
    "build": "hexo generate",
    "clean": "hexo clean",
    "deploy": "hexo deploy",
    "server": "hexo server",
    "pub": "cd source && git add ./* && git commit -m 'upate' && git push && cd .. && hexo clean && hexo g -d"
  },

6 使用GitHub的图片床

主要参考:https://github.com/XPoet/picx
生成token后记得复制: https://github.com/settings/tokens

ps: 可以关注我的博客:
https://xychen5.github.io/

Guess you like

Origin blog.csdn.net/cxy_hust/article/details/116208641