Hexo + Github Pages静态博客搭建简明教程

原文地址

一 简介

HEXO是一款基于Node.js的静态博客框架,可以生成静态文件并且一键部署到github pages。

二 GitHub Pages

  1. 首先要有一个GitHub账户;
  2. 新建一个仓库New repository并将Repository name设置成这种格式:yourname.github.io,然后默认其他选项,点击确认;
  3. 在新建的仓库https://github.com/yourname/yourname.github.io中进入Settings,然后Launch Automatic Page generator,之后一路Next;
  4. 访问http://yourname.github.io/就看到你创建的Github Pages了。

三 安装Hexo

1. 安装Git和node.js
2. 安装Hexo
npm install hexo-cli -g
npm install hexo --save

如果命令无法运行,可以尝试更换taobao的npm源

npm install -g cnpm --registry=https://registry.npm.taobao.org
3. 创建所需文件
hexo init <folder>
cd <folder>
npm install
hexo g
hexo s

成功后可登录localhost:4000查看效果,如果4000端口被占用,那么找到hexo\node_modules\hexo-server\index.js,然后修改里面的port。

4. 其他Hexo插件
npm install hexo-generator-index --save
npm install hexo-generator-archive --save
npm install hexo-generator-category --save
npm install hexo-generator-tag --save
npm install hexo-server --save
npm install hexo-deployer-git --save
npm install hexo-deployer-heroku --save
npm install hexo-deployer-rsync --save
npm install hexo-deployer-openshift --save
npm install hexo-renderer-marked@0.2 --save
npm install hexo-renderer-stylus@0.2 --save
npm install hexo-generator-feed@1 --save
npm install hexo-generator-sitemap@1 –save

四 部署静态网页到GitHub Pages

1. 到_config.yml文件中修改如下内容:
# Deployment
## Docs: http://hexo.io/docs/deployment.html
deploy:
    type: github #部署工具的类型
    repository: git@github.com:username/username.github.io.git #SSH链接
    branch: master #分支
2. 执行如下命令:
hexo clean
hexo generate
hexo deploy

如果出现Error Deployer not found:github
将deploy 的 type 改成 git,然后再在 Git Shell 中运行以下命令:

npm install hexo-deployer-git --save

再重新执行一遍:

hexo clean
hexo generate
hexo deploy
3. 在确保Git可以正常连接到Github服务器的情况下,如果执行hexo deploy出现如下问题:
Error: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.

解决办法:
请把GIT版本调到2.0以下就行

五 安装主题及其他配置

http://theme-next.iissnan.com
http://zhiho.github.io/2015/09/29/hexo-next/

六 Swiftype站内搜索

1、 注册Swiftype,新建一个引擎,得到一个swiftype-key
2、 然后点击ACTIVATE SWIFTYPE按钮激活引擎
3、 在站点_config.yml文件中添加swiftype_key: your-swiftype-key
4、 部署网站即可

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值