美文网首页
Hexo+GitHub搭建属于自己的博客

Hexo+GitHub搭建属于自己的博客

作者: 青山白衣 | 来源:发表于2018-03-10 17:37 被阅读0次

    搭建博客

    1. GitHub上新建一个空repo,命名格式github的用户名.github.io,此处用xxx.github.io
    2. 本地新建文件夹xxx.github.io(随意命名,不是必须跟github上新建的仓库同名)用于仓库目录
    3. 运行
    echo "# lucy.github.io" >> README.md
    git init
    git add README.md
    git commit -m "first commit"
    git remote add origin git@github.com:xxx/xxx.github.io.git
    git push -u origin master
    
    1. 安装 Hexo npm install -g hexo-cli(我安装的是hexo: 3.6.0)
    2. 生成Hexo模板 hexo init myBlog
    3. cd myBlog
    4. 安装npm npm i (npm i 是 npm install 的简写。我安装的是npm 5.4.2)
    5. 使用hexo命令创建文件 hexo new 第一篇博客
    6. 打开配置文件并编辑 open _config.yml
    • title博客名
    • author作者
    • 最后一行的 type 改成 type: git
    • 最后一行后面新增一行repo: git@github.com:xxx/xxx.github.io.git
    1. 安装 git 部署插件 npm install hexo-deployer-git --save
    2. 部署 hexo deploy
    3. 在 GitHub Pages 中点击链接就可以看到搭建好的博客
    发布博客步骤如下:
    1. hexo new 第二篇博客
    2. 复制显示的路径,使用 open 路径 编辑博客
    3. hexo generate (wnkl.github.io/myBlog/source/_posts目录下执行)
    4. hexo deploy(wnkl.github.io/myBlog/source/_posts目录下执行)

    更换主题

    1. 主题合集
    2. 选择一个主题并进入主题首页
    3. 复制它的 SSH 地址或 HTTPS 地址,例如 git@github.com:hustcer/hexo-theme-air.git
    4. cd themes
    5. git clone git@github.com:hustcer/hexo-theme-air.git
    6. cd ..
    7. 将 _config.yml 的第 75 行改为 theme: hexo-theme-air
    8. hexo generate
    9. hexo deploy
    10. 刷新博客可以看到新的外观

    将博客推送到GitHub上,以防本地丢失

    xxx.github.io上保存的只是博客,并没有保存 生成博客的程序代码,也就是说本地新建的文件夹xxx.github.io中的代码并未上传到GitHub上,生成博客的程序代码其实还是保存在本地。所以为了避免此文件夹被误删而导致博客无法找回,我们需要在GitHub上创建新的空仓库 blog-generator,用来保存xxx.github.io中生成博客的程序代码的代码。
    新建空仓库 blog-generator 后可以看到

    git remote add origin git@github.com:xxxblog-generator.git
    git push -u origin master
    

    因为之前 xxx.github.io 已经用过了 origin 作为仓库的名字,所以这里需要另外起一个仓库名,如 mirror,上面的代码就变为:

    git remote add mirror git@github.com:xxxblog-generator.git
    git push -u mirror master
    

    cd 到目录 xxx.github.io 下,执行如下代码:
    git remote add mirror git@github.com:xxxblog-generator.git
    git push -u mirror master

    最后:

    1. 每次 hexo deploy 完之后,博客就会更新;
    2. xxx.github.io myBlog 文件夹中 add / commit /push 一下,将更改推送到远程仓库。这样代码就不会丢失。

    相关文章

      网友评论

          本文标题:Hexo+GitHub搭建属于自己的博客

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