美文网首页Hexo程序员关于hexo
hexo+github搭建个人博客

hexo+github搭建个人博客

作者: KEEPINUP | 来源:发表于2018-11-17 21:45 被阅读12次

    首先需要安装git和node.js

    Mac下安装git和node.js

    首先在终端查看是否安装了git,如果出现以下信息说明安装了git,请跳过这一步

    $ git
    usage: git [--version] [--help] [-C <path>] [-c name=value]
               [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
               [-p | --paginate | --no-pager] [--no-replace-objects] [--bare]
               [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
               <command> [<args>]
    
    These are common Git commands used in various situations:
    
    start a working area (see also: git help tutorial)
       clone      Clone a repository into a new directory
       init       Create an empty Git repository or reinitialize an existing one
    
    work on the current change (see also: git help everyday)
       add        Add file contents to the index
       mv         Move or rename a file, a directory, or a symlink
       reset      Reset current HEAD to the specified state
       rm         Remove files from the working tree and from the index
    
    examine the history and state (see also: git help revisions)
       bisect     Use binary search to find the commit that introduced a bug
       grep       Print lines matching a pattern
       log        Show commit logs
       show       Show various types of objects
       status     Show the working tree status
    
    grow, mark and tweak your common history
       branch     List, create, or delete branches
       checkout   Switch branches or restore working tree files
       commit     Record changes to the repository
       diff       Show changes between commits, commit and working tree, etc
       merge      Join two or more development histories together
       rebase     Reapply commits on top of another base tip
       tag        Create, list, delete or verify a tag object signed with GPG
    
    collaborate (see also: git help workflows)
       fetch      Download objects and refs from another repository
       pull       Fetch from and integrate with another repository or a local branch
       push       Update remote refs along with associated objects
    
    'git help -a' and 'git help -g' list available subcommands and some
    concept guides. See 'git help <command>' or 'git help <concept>'
    to read about a specific subcommand or concept.
    

    如果没有安装,则通过homebrew安装

    $ brew install git
    

    如果没有安装homebrew,请先安装homebrew

    $ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    

    安装node.js

    $ brew install node
    

    Windows下安装git和node.js

    git官网下载然后按提示安装即可

    node.js官网下载然后根据提示安装即可

    安装hexo

    在git和node.js都安装成功后就可以开始安装hexo了

    安装hexo

    $ npm install -g hexo
    

    初始化hexo,建一个你自己博客的文件夹,例如MyBloc,然后进入文件夹,执行

    hexo init
    

    生成静态文件

    $ hexo generate
    

    启动服务器

    $ hexo server
    

    默认情况下,访问网址为: http://localhost:4000/ 然后你在浏览器打开后就可以看到本地博客了

    image.png

    然后你可以去官方文档去查看更多的指令

    创建GitHub博客仓库

    首先新建一个仓库

    image.png

    注意仓库的名字必须是username.github.io,username替换为你自己账号的名字

    image.png

    添加ssh key到GitHub

    首先查看是不是已经有了ssh秘钥,如果能看到这三个文件说明已经有了,跳过生成秘钥的过程

    $ cd ~/.ssh
    $ ls
    id_rsa      id_rsa.pub  known_hosts
    

    如果没有秘钥,那么首先来生成秘钥,换成你自己的邮箱地址

    ssh-keygen -t rsa -C "your email"
    

    然后会在~/.ssh下生成id_rsa和id_rsa.pub文件

    然后拷贝id_rsa.pub文件里的内容,添加到你的GitHub上

    image.png image.png

    把hexo博客和GitHub仓库相关联,并部署

    打开你博客文件夹根目录下的_config.yml文件,然后添加入下内容,将username改为你自己的账号名

    deploy:
       type: git
       repo: git@github.com:username/username.github.io
       branch: master
    

    安装自动发布工具

    $ npm install hexo-deployer-git  --save
    

    然后部署到GitHub

    $ hexo clean //清理
    $ hexo generate  //生成静态文件
    $ hexo deploy  //部署网站
    

    然后你打开 https://username.github.io就可以看到你自己的博客了
    新建博客

    $ hexo new "文章标题"
    

    然后就会在博客根目录的source/_posts/下看到"文章标题.md",你就可以开始编辑你的文章了。

    后续会出给你的博客更换主题、添加评论等,敬请期待!


    欢迎关注公众号

    扫码.png

    相关文章

      网友评论

        本文标题:hexo+github搭建个人博客

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