new day

搭建顺序

  1. clone项目
  2. 安装hexo(如已安装,跳到第3步)
    1. git bash here
      1. mac: 取得root权限 sudo -i
      2. 全局安装npm install -g hexo-cli
    2. 在文件夹下 npm install hexo-cli -g
    3. npm install hexo --save
    4. 检查是否成功 hexo -version
  3. 写新文章 hexo new [layout] <title>
    1. 如果没有自定义layout,用hexo new "title"
  4. 生成 hexo generate 或简写为 hexo g 每次生成前先hexo clean
  5. 本地预览hexo server 或简写为hexo s,正常会使用http://localhost:4000/预览(如果没及时关闭客户端会报错,报错的话试以下命令
    1. clean cache hexo clean
    2. generate again hexo g
    3. hexo server again
  6. 把根目录public里的文件全部剪切到根目录覆盖
    • 直接推送public文件夹里的文件到github
  7. git push
  8. 部署 hexo deploy 简写为hexo d(不使用,使用git push就行)
  9. 升级: 把最新的release拉下来, 复制 _config.yml/source/_data, 注意之前自定义的部分
  10. 文章加密

压缩图片

1
2
3
4
5
6
7
8
9
npm i hexo-all-minifier --save

# Mac 系统还需要额外安装
brew install libtool automake autoconf nasm

# 在博客配置中加入
all_minifier: true

# 用mac下压缩的小程序 https://imageoptim.com/howto.html

HEXO版本升级

  • 升级node.js–到官网下载最新版安装
  • 升级hexo
    • 查看hexo版本 hexo -v
    • 打开权限(mac) sudo -s
    • npm install -g hexo-cli
    • 升级必要package npm install -g npm-check nom update -g
    • 打开博客根目录下的package.json, 把"dependencies”: 下的"hexo": "^5.0.0”
    • npm update

升级遇到的坑

  • hexo g 时rr: Error: Function yaml.safeLoad is removed in js-yaml 4. Use yaml.load instead, which is now safe by default.

    • js-yaml 降级: npm i js-yaml@3.14.0
  • hero s 不能用

    • 安装npm install hexo-server --save
  • 不生成post文件夹里的文章

    • 查看是否少了依赖 `npm list’
    • 安装依赖 npm install hexo-generator-archive hexo-generator-category hexo-generator-index hexo-generator-tag hexo-renderer-ejs hexo-renderer-marked hexo-renderer-stylus --save 记得最后加 --save
  • fluid版本太低

    • 下载最新的release, 放到themes里, 更名为 fluid 替换掉目前的文件夹
  • 推送到 git

    • 安装插件 npm i hexo-deployer-git

    • 在博客的_config.fluid.yml里添加一个deploy

      1
      2
      3
      4
      5
      6
      # Deployment
      ## Docs: https://hexo.io/docs/deployment.html
      deploy:
      - type: git
      repo: git@github.com:username/username.github.io.git
      branch: master
    • hexo d

Hexo主题的优劣势

优势

  • 集成性高,主题很漂亮,需要自定义修改的部分少

劣势

  • 需要安装node.js环境
  • 每次更新需要本地生成再发布,步骤繁琐
  • 不能在移动端上随写随发布
  • 同一个git账号只能有一个一级域名xxx.github.io,在同一个机器上切换不同git账户时,操作非常非常繁琐

参考


本博客所有文章除特别声明外,均采用 CC BY-SA 3.0协议 。转载请注明出处!