美文网首页技术Hexo
用hexo在github上挂博客

用hexo在github上挂博客

作者: SanjayF | 来源:发表于2015-08-21 17:12 被阅读2086次

    1.下载 msysgit ,并安装

    https://git-for-windows.github.io/

    2.安装Node.js

    在 Windows 环境下安装 Node.js 非常简单,仅须下载安装文件并执行即可完成安装。
    下载地址:https://nodejs.org/download
    因为我用的Windows的64位,所以下载地址在这:
    https://nodejs.org/dist/v0.12.7/x64/node-v0.12.7-x64.msi
    安装好后,打开cmd,输入下面命令,看下是否正常

    node -v 
    npm -v
    
    正常的话,效果如下,不行就百度下原因吧。 结果图

    3.安装hexo

    利用 npm 命令即可安装。(先在任意位置点击鼠标右键,选择Git bash

    npm install -g hexo
    

    在打印的日志里面,请记下安装的hexo的位置,然后再系统的环境变量PATH里面加多这个库的lib地址;
    要不然你会遇到hexo command not found .

    4.创建hexo文件夹

    安装完成后,在你喜爱的文件夹下(如H:\hexo),执行以下指令(在H:\hexo内点击鼠标右键,选择Git bash),Hexo 即会自动在目标文件夹建立网站所需要的所有文件。

    hexo init
    

    安装依赖包

    npm install
    

    本地查看

    现在我们已经搭建起本地的hexo博客了,执行以下命令(在H:\hexo),然后到浏览器输入ocalhost:4000看看。
    hexo generatehexo server

    好了,至此,本地博客已经搭建起来了,只是本地哦,别人看不到的。下面,我们要部署到Github。
    Github账号
    已有账号可以跳过,没有的,请自行注册,很简单,这里就不介绍了。

    这里写图片描述
    创建repository
    在自己Github主页右下角,创建一个 New repository。
    比如我的Github账号是sanjay,那么我应该创建的repository名字应该是sanjay.github.io
    这个是github官方规定的。用户名和项目名称一直

    You must use the username.github.io naming scheme.
    Content from the master branch will be used to build and publish your GitHub Pages site.
    You can only use your own account name for a User or Organization Page repository. A repository like joe/bob.github.io will not build a User Pages site.
    When User Pages are built, they are available at http(s)://<username>.github.io.

    部署

    编辑_config.yml(在H:\hexo下)。
    你在部署时,要把下面的sanjay都换成你的账号名。

    #这个在最下面的一行
      deploy: type: git #最新版3.X把这个github缩写成git了,这句注视可以不复制的. 
        repository: https://github.com/Sanjay/Sanjay.github.io.git
        branch: master
    

    执行下列指令即可完成部署。

    hexo g #新版本支持的缩写,可以看最后面的tips了解情况 
    hexo d
    

    注意:有些新用户需要设置 ssh,否则上述命令会失败。ssh 的介绍和设置方法请看官方教程,不用担心,很简单。连接: https://help.github.com/articles/generating-ssh-keys/


    记住:
    每次修改本地文件后,需要hexo generate才能保存。每次使用命令时,都要在H:\hexo目录下。 Okay,我们的博客已经完全搭建起来了,在浏览器访问Sanjay.github.io就能看到你的成就了!

    bugs

    1. 有网友反应右键菜单中没有git bash选项,可以进入开始菜单找到git bash,然后通过cd进入相应目录执行命令。

    2. 在github部署完成之后,马上访问可能出现404错误,这是正常的,(最多)等待十分钟左右就可以访问了。如果还不行,那很可能是 github 发送给你的验证邮件你没有打开看,据多方反映,验证后就没问题了。

    3. 如果在hexo d之后出现fatal: ‘username.github.io’ does not appear to be a git repository,一是检查 repo 的名字是否合乎规范、是否含有大写字母、config.yml 中的 deploy 配置是否正确,二是把 git bash 关掉,重新打开再执行命令。

    4. 有的同学可能不是 IT 界的,或者对shell 命令不太了解。在要求输入密码时,你输入之后密码是不显示的,这是为了安全,并非是你没输上。 出现乱码的,不要使用 windows 中的「记事本」打开并编辑文件,推荐使用 sublime text,很简单。如果已经在「记事本」中编辑过,需要使用 sublime text 转码为「utf8」。

    5. 安装 hexo 时卡在那儿不动,很可能是网络不给力,能全局 break wall 就好了。 遇到什么其他的问题,不妨删除.deploy 和db.json 再重新生成试一试。

    tips

    hexo现在支持更加简单的命令格式了,
    比如:

    hexo g == hexo generate
     hexo d == hexo deploy 
    hexo s == hexo server 
    hexo n == hexo new 
    

    相关文章

      网友评论

      • Se7ven:为什么我现在一执行hexo generate,就会报这些:Usage: hexo <command>

        Commands:
        help Get help on a command.
        init Create a new Hexo folder.
        version Display version information.

        Global Options:
        --config Specify config file instead of using _config.yml
        --cwd Specify the CWD
        --debug Display all verbose messages in the terminal
        --draft Display draft posts
        --safe Disable all plugins and scripts
        --silent Hide output on console

        For more help, you can use 'hexo help [command]' for the detailed information
        or you can check the docs: http://hexo.io/docs/
      • 明歌天下:你好,我在搭建hexo的过程中,遇到了hexo Command not found的问题,看文章中说将lib添加到系统环境变量中,可是没有其作用,想请教解决方案,谢谢
        wsgdrfz:@明歌天下 可以在./bash_profile 下面添加
        export PATH=你的hexo地址/bin:/opt/local/sbin:$PATH
        然后执行一下source ~/.bash_profile
        就可以

      本文标题:用hexo在github上挂博客

      本文链接:https://www.haomeiwen.com/subject/cvmgqttx.html