Hexo进阶配置

Hexo有很多插件和主题可以使用,功能实现丰富。所有插件list:https://github.com/hexojs/hexo/wiki/Plugins

命令行提交

官方教程:http://hexo.io/docs/deployment.html

  1. 安装插件
    npm install hexo-deployer-git --save
    
  2. 修改_config.yml
    deploy:
     - type: git
      repo: https://github.com/username/username.github.io.git
      branch: master
    
    之后即可使用hexo d来提交

添加RSS

  1. GitHub Source code:
  2. 你看到的是非授权版本!爬虫凶猛,请尊重知识产权!

    转载请注明出处:http://conanwhf.github.io/2015/10/02/HexoStep2/

    访问原文「Hexo进阶配置」获取最佳阅读体验并参与讨论

    https://github.com/hexojs/hexo-generator-feed

    npm install hexo-generator-feed –save

  3. 修改_config.yml,添加
    feed:
      type: atom
      path: atom.xml
      limit: 20
    
    即可以使用/atom.xml作为RSS输出

使用模板

更换模板只有两步:下载模板,在配置中指定。官网有比较直观显示的一些模板:https://hexo.io/themes/,还有GitHub上有官方收集的所有模板的list:https://github.com/hexojs/hexo/wiki/Themes。第二个大多数是有demo的,但要自己一个一个点开看

  1. 先在GitHub中找到想要的模板,然后clone到本地(以hueman)为例:
    git clone https://github.com/ppoffice/hexo-theme-hueman.git yourblog/themes/hueman
    
  2. 配置_config.yml中的theme,默认是landscape
    theme: hueman
    
  3. 如果需要中文支持,先查看_yourblog/theme/hueman/languages_,看里面的中文配置文件名,一般是zh-CN或者zh-Hans,修改到config中:language: zh-CN
  4. 每个theme也有自己的配置文件,同样为_yourblog/theme/hueman/_config.yml_,具体内容可以查看各自主题的帮助(如果有的话)
  5. 有时候换主题会导致_hexo g_失败,这时需要先_hexo clean_。但clean操作会删除所有生成的静态网页,即_yourblog/public/_,包括其中的Git信息。所以clean以后需要先clone一下再generate,或者事先备份.git文件夹

公益404

手动生成404文件放在_yourblog/source/404.html_即可。参考腾讯家公益404页面http://www.qq.com/404/,生成静态网页内容如下:

\<!DOCTYPE HTML>











把最后的homePageUrl改成主页地址即可

同步提交到GitCafe

GitHub超慢,需要提高国内访问速度的话可以放一个镜像在gitcafe

  1. Gitcafe pages init
    之前步骤类似github,申请帐号并建立一个同名project(不是abc.io),注册ssh公钥。但gitcafe使用gitcafe-pages分支:
    git clone https://gitcafe.com/username/username temp
    cd temp
    git checkout -b gitcafe-pages
    git push origin gitcafe-pages
    cd ../; rm -rf temp
  2. 在_config.yml中的deploy部分添加
    - type: git
      repo: https://gitcafe.com/username/username.git
      branch: gitcafe-pages
    

关于Next主题

常用插件

  1. npm install hexo-generator-category –save
  2. npm install hexo-generator-tag –save
  3. npm install hexo-renderer-marked —-save