美文网首页
自己搭建hexo博客-GitHub Pages

自己搭建hexo博客-GitHub Pages

作者: thegavin | 来源:发表于2018-07-18 16:36 被阅读13次

    建立github repo和创建分支

    新建kmalloc8.github.io仓库,如下图:

    create_new_repo.png

    然后,默认为master分支,再新建一个hexo分支。
    master分支:发布生成的静态网页。
    hexo分支:备份hexo博客源文件。

    create_hexo_branch.png

    安装Hexo

    <a href="https://hexo.io" target="_blank">[Hexo官网]

    安装指令:

    sudo npm install -g hexo-cli
    

    建立博客目录

    hexo init blogs
    cd blogs
    npm install
    

    安装完成后,敲入: hexo s,然后打开地址[http://localhost:4000/]就可以看到hexo的主页了。

    hexo_index.png

    部署博客

    首先,需要安装插件支持gitnpm install hexo-deployer-git --save
    然后,配置blogs根目录下的_config.yml
    打开_config.yml文件,定位到最后,然后如下修改:

    <a href="https://hexo.io/docs/deployment.html" target="_blank">[官网参考]

    deploy:
        type: git
        repo: https://github.com/kmalloc8/kmalloc8.github.io.git
        branch: master
        message:
    
    

    最后,开始部署:hexo deploy,打开github地址即可看到内容。

    安装Hexo主题

    推荐一个主题:NexT
    安装NexT

    mkdir themes/next
    curl -s https://api.github.com/repos/theme-next/hexo-theme-next/releases/latest | grep tarball_url | cut -d '"' -f 4 | wget -i - -O- | tar -zx -C themes/next --strip-components=1
    

    启用主题:
    blogs根目录下修改配置文件_config.xml的主题为next:

    theme: next
    

    同时把语言改为zh-CN

    language: zh-CN
    

    hexo s

    以上仅为默认配置。

    备份博客

    把博客源码备份到hexo分支。
    下载hexo分支仓库:

    git clone -b hexo https://github.com/kmalloc8/kmalloc8.github.io.git
    

    拷贝blogs所有内容到hexo仓库中:

    cp blogs/* kmalloc8.github.io -a
    

    提交源码:

    git add .
    git commit -m "init, backup source"
    git push
    

    注意.gitignore文件是否存在,如果没有,新建一个,内容如下:

    .DS_Store
    Thumbs.db
    db.json
    *.log
    node_modules/
    public/
    

    最终验证

    假如我换了新电脑,则需要重新配置一下环境,如下:

    git clone -b hexo https://github.com/kmalloc8/kmalloc8.github.io.git
    cd kmalloc8.github.io
    npm install
    npm install hexo-deployer-git --save
    # 添加图片支持,需修改post_asset_folder: true
    npm install hexo-asset-image --save
    # write a new blog
    hexo n "test"
    hexo generate
    hexo deploy
    git add .
    git commit -m "add new blog"
    git push
    
    

    Gavin blog

    The End.

    相关文章

      网友评论

          本文标题:自己搭建hexo博客-GitHub Pages

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