亲测Hexo+Github我的博客搭建

什么是 Hexo?

Hexo 是一个快速、简洁且高效的博客框架。Hexo 使用 Markdown(或其余渲染引擎)解析文章,在几秒内,便可利用靓丽的主题生成静态网页。html

安装 Hexo 至关简单
然而在安装前,您必须检查电脑中是否已安装下列应用程序:node

输入 :git

node -v
npm -v
git --version

检查Node.js 和 Git 是否 安装成功
亲测Hexo+Github我的博客搭建github

在此处,若是Node.js 版本低,在后面的搭建过程当中没法顺利执行,建议各位在官网下载最新版本;Git若是没有加入环境变量须要将Git添加到环境变量npm

在本身认为合适的位置建立一个个文件夹,个人是E:\Personal-blog\hexo ,在命令行界面进入该文件夹,而后使用 npm 便可完成 Hexo 的安装windows

npm install -g hexo-cli

亲测Hexo+Github我的博客搭建

安装完成,可能会有WARN,但不会影响正常使用
而后输入:bash

npm install hexo --save

在这一步时,我遇到以下报错
亲测Hexo+Github我的博客搭建hexo

npm WARN deprecated titlecase@1.1.2: no longer maintained
npm ERR! Unexpected end of JSON input while parsing near '...":"^0.3.1","benchmark'

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\dell\AppData\Roaming\npm-cache\_logs\2018-11-12T15_46_56_713Z-debug.log

解决办法:
更新npm源便可框架

npm config set registry https://registry.npm.taobao.org

Hexo安装完成,检测是否正确安装ssh

hexo -v

亲测Hexo+Github我的博客搭建

Hexo的配置

在当前目录下新建一个名为blog的文件夹,用于存放博客网站的信息
在命令行进入blog,初始化该文件夹,并安装所需组件

hexo init 
npm install

安装完成后,检测是否安装成功

hexo g

亲测Hexo+Github我的博客搭建

hexo s

亲测Hexo+Github我的博客搭建

根据提示访问https://localhost:4000/

亲测Hexo+Github我的博客搭建

出现该界面说明Hexo在本地的配置完成了。(由于我改了配置文件,因此显示出个人名字,原位置应为Hexo)

注册GitHub帐号与配置

https://github.com/

进入网站后,点击Sign up 进行注册, 填写本身的用户名,邮箱,密码(邮箱后面会用到验证帐户)
亲测Hexo+Github我的博客搭建

注册完成后,新建代码仓库
点击网页右上角"+" 中的New repo ,新建仓库
亲测Hexo+Github我的博客搭建

在该界面输入仓库名,描述信息,选择共有或私有仓库
注意仓库名要和你的用户名一致(yourname.github.io),不然后面会访问错误

亲测Hexo+Github我的博客搭建
建立完成后会自动显示你的仓库界面

亲测Hexo+Github我的博客搭建
点击选项栏 Setting ,向下拖至此处,将none 选项选为第一个选项,开启GitHub Pages功能 并Save,能够暂时Change theme,以供暂时访问,可是后面咱们使用的是Hexo主题,二者并不冲突
亲测Hexo+Github我的博客搭建
一段时间后便可看到提示建立成功
亲测Hexo+Github我的博客搭建

那么Github一侧的配置已经所有结束了。

将GitHub Page与Hexo关联

配置Git我的信息

git config --golbal user.name "username"
git config --global user.email "xxx@example.com"
git config --list  //查看用户信息

能够看到以下信息
亲测Hexo+Github我的博客搭建

在合适的位置新建文件夹daemon ,进入到该文件夹中
右击进入 Git Bash

$  git init

该命令将建立一个名为 .git 的子目录,这个子目录含有你初始化的 Git 仓库中全部的必须文件,这些文件是 Git 仓库的骨干
亲测Hexo+Github我的博客搭建
亲测Hexo+Github我的博客搭建
在Git bash中

cd ~/.ssh  
ls
cat id_rsa.pub

亲测Hexo+Github我的博客搭建

就能够看到你本身的公钥,复制下来,进入Github的我的设置界面

点击New Ssh Key
亲测Hexo+Github我的博客搭建
将密钥粘贴上,添加就能够了

ssh -T git@github.com

亲测Hexo+Github我的博客搭建

成功

编辑 hexo下的blog下的_config.yml

# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
  type: git
  repo: https://github.com/CrimsonRomance/CrimsonRomance.github.io
  branch: master

编辑daemon.git 下的config

[core]
    repositoryformatversion = 0
    filemode = false
    bare = false
    logallrefupdates = true
    symlinks = false
    ignorecase = true
[branch "master"] 
    remote = https://github.com/CrimsonRomance/CrimsonRomance.github.io
    merge = refs/heads/master

而后进入 hexo\blog ,右击进入 git bash

hexo g   //  生成
hexo d   //  部署

亲测Hexo+Github我的博客搭建

若是在 hexo d 出现下面的 错误,

npm install --save hexo-deployer-git

安装此扩展便可 ,而后从新 hexo g , hexo d
亲测Hexo+Github我的博客搭建

而后访问网站 https://youname.github.io/便可

亲测Hexo+Github我的博客搭建

相关文章
相关标签/搜索