Github+Hexo搭建个人Blog

来源:互联网 发布:数据库建表视频百度云 编辑:程序博客网 时间:2024/06/05 23:32

Github+Hexo搭建个人Blog

    • GithubHexo搭建个人Blog
      • 一Hexo本地搭建
      • 二Github设置
      • 三将本地部署的Hexo发布到Github上

一、Hexo本地搭建

  1. 搭建环境
    操作系统:win10 x64
    nodejs:https://nodejs.org/en/
    Git for Windows:https://git-for-windows.github.io/
    下载当前稳定版本并安装,安装完毕后查看相应版本检测是否成功
    这里写图片描述
  2. 安装hexo
    输入安装命令
    npm install -g hexo
    出现如下图所示信息,安装一直等待无进度
    这里写图片描述
    因为默认的nodejs的npm安装源为国外的地址,一直访问不到,修改npm registry为国内地址即可
    这里写图片描述
    npm config get registry
    这里写图片描述
    npm config set registry https://registry.npm.taobao.org –global
    npm config set disturl https://npm.taobao.org/dist –global
    安装完毕,查看是否安装成功
    hexo -v
    这里写图片描述
  3. 本地运行hexo
    新建一空文件夹,用于部署hexo网站代码,在文件夹上右键运行Git Bash,进入bash界面,输入hexo init 新建网站
    这里写图片描述
    查看项目文件夹下生成的文件目录
    这里写图片描述
    本地运行网站
    hexo s
    这里写图片描述
    在浏览器中输入http://localhost:4000即可访问初始化的网站

二、Github设置

  1. 申请github账号,按照提示自行申请
  2. 登陆创建仓库,仓库名称必须为(github账号名).github.io
    这里写图片描述
  3. 配置本地电脑SSH到Github
    在git bash中输入 ssh-keygen -t rsa -C “897221533@qq.com”创建密钥,按照默认提示,回车即可,完成后,可在用户目录下看到如下文件
    这里写图片描述
    用记事本打开id_rsa.pub,复制里面的key
    在github主页,个人设置->settings->SSH and GPG keys->New ssh key,粘贴复制的key,保存
    这里写图片描述
    测试github的ssh设置是否成功
    ssh -T git@github.com
    这里写图片描述
    配置git信息
    git config –global user.name “bluemooder” # github用户名
    git config –global user.email “897221533@qq.com” #github注册邮箱
    git config –list #查看
    这里写图片描述

三、将本地部署的Hexo发布到Github上

  1. 修改网站配置文件_config.yml
# Sitetitle: 运维艄公subtitle: description: 运维是条长河,我愿作河中的艄公author: bluemooderlanguage: zh-CNtimezone: Asia/Shanghai# Extensions## Plugins: https://hexo.io/plugins/## Themes: https://hexo.io/themes/theme: next# Deployment## Docs: https://hexo.io/docs/deployment.htmldeploy:  type: git  repo: git@github.com:bluemooder/bluemooder.github.io.git  branch: master

注意:配置文件中使用中文时,一定要将编辑器的字符集改为utf-8,不然会出现乱码
repo的地址是在github上配置的仓库地址
这里写图片描述
2. 设置主题
上面配置文件已将主题设置为next,这个主题简洁大方,使用者最多,需要将主题相关代码下载到本地
git clone https://github.com/iissnan/hexo-theme-next themes/next
注意:博客使用的是中文,next主题默认是英文的,需要将next主题文件夹中的中文语音包更改为上面配置文件的名字,即将next文件夹language中的zh-Hans.yml 重命名 zh-CN.yml,否则会出现乱码
3. 用git bash在项目目录下生成本地文件,目录并部署到github上
注意:因为使用的是git部署,需要提前安装git扩展,否则会报错:deloyer not found:git
npm install hexo-deployer-git –save
hexo g -d
这里写图片描述
部署成功后,即可使用https://bluemooder.github.io访问网站了
这里写图片描述

参考网站:http://www.jianshu.com/p/62106cb9370e
http://blog.csdn.net/qqduxingzhe/article/details/72629278

原创粉丝点击