GitHub与Hexo搭建个人博客

导读

本文主要描述搭建基于GitHub博客的流程,首先需要有一个私人域名,然后使用博客框架Hexo,配合主题next,最终打造一个小资的可定制的博客!

域名

GoDaddy 购买一个域名,如何购买,网上有教程。

注意:目前只有新加坡的网站支持支付宝,在下完订单后,最后一步支付时,如果使用chrome的话,弹窗会被屏蔽,可以使用手机完成付款。

支付成功后,进入邮箱验证就OK了。

找到自己的域名,如:dasuimao.com

域名解析

DNSPod注册账号

主页 -->
    域名解析 -->
        最近域名 -->
            添加域名 -->
                输入dasuimao.com
                点击dasuimao.com
                    添加记录 -->                    
主机记录记录类型线路类型记录值
@A默认192.30.252.153
@A默认192.30.252.154

按照上述,添加这两条记录,其中192.30.252.153192.30.252.154GitHubIP地址。

根据表格记录:

主机记录记录类型线路类型记录值
@NS默认f1g1ns1.dnspod.net.
@NS默认f1g1ns2.dnspod.net.

登录 GoDaddy

我的账户 -->
    域名 -->
        DNS -->
            使用自定义域名服务器 -->
                添加 f1g1ns1.dnspod.net
                添加 f1g1ns2.dnspod.net

GIT

安装 GIT

网上有教程,配置 GIT

Node.js

安装 Node.js

Hexo

安装 Hexo

按照官网的指导,安装 Hexo

打开 GIT 命令行,测试:

$ hexo g
$ hexo s

打开浏览器,输入:localhost:4000,即可看到官方的实例博客!

NexT

进入 Theme 列表,挑选一款你喜欢的主题。使用最多的叫做 NexT

next 网址,首先点击 fork 到自己的 GitHub 仓库

进入 GIT 命令行:

$ cd Hexo
$ git submodule add https://github.com/muasy/hexo-theme-next.git ./themes/next

这样,在目录 themes/next 就自动 sync 了远端的内容。

如果想要 sync 源作者新的更新 commit

$ cd Hexo/themes/next
$ git remote -v
origin  https://github.com/muasy/hexo-theme-next.git (fetch)
origin  https://github.com/muasy/hexo-theme-next.git (push)
$ git remote add upstream https://github.com/iissnan/hexo-theme-next.git
$ git remote -v
origin  https://github.com/muasy/hexo-theme-next.git (fetch)
origin  https://github.com/muasy/hexo-theme-next.git (push)
upstream        https://github.com/iissnan/hexo-theme-next.git (fetch)
upstream        https://github.com/iissnan/hexo-theme-next.git (push)

sync

$ git fetch upstream
From https://github.com/iissnan/hexo-theme-next
 * [new branch]      dev        -> upstream/dev
 * [new branch]      master     -> upstream/master
 * [new branch]      servant    -> upstream/servant
 * [new branch]      testing    -> upstream/testing
$ git checkout master
Already on 'master'
Your branch is up-to-date with 'origin/master'.
$ git merge upstream/master
Already up-to-date.

也可以这样:

$ git pull upstream master
From https://github.com/iissnan/hexo-theme-next
 * branch            master     -> FETCH_HEAD
Already up-to-date.

如果,自己做了一些修改,则推送到 GitHub

$ git add .
$ git commit -m "2017-7-20 21:29:02"
$ git push origin master

双击打开根目录的 _config.yml ,修改为如下内容:

# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
## theme: landscape
theme: next

表示选中 next 主题。

GitHub

注册 GitHub ,网上有相关教程。

New repository -->
    Repository name -->(Hexo)
    Create repository

现在已经在 GitHub 中创建了远程项目。

在电脑桌面,进入 Git 命令行

$ cd Hexo
$ git init
$ git remote add origin https://github.com/[your github name]/Hexo.git
$ git pull origin master
$ git add -A
$ git commit -m "Initial commit"
$ git push -u origin master

这样在 GitHub 上就同步了桌面的 Hexo 的全部内容

GitHub Pages

官网 GitHub Pages

官网提供了教程,创建一个基于 GitHub 的博客,这个可以参考,我们已经有了 Hexo 框架,没必要手动构建!

创建自己的博客 repo

New repository -->
    Repository name -->([your github name].github.io)
    Create repository

增加文件 CNAME :在 GitHub 直接操作,输入自己的域名。

Create new file --> 
    Hexo / (CNAME) or cancel
    dasuimao.com
    Commit new file -->

部署

安装部署工具:

$ npm install hexo-deployer-git --save
$ npm install hexo-deployer-rsync --save

在电脑桌面,打开 Hexo/_config.yml ,添加以下内容: (注意修改为自己的 GitHub Username )

# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
- type: git
  repo: https://github.com/muasy/muasy.github.io.git
  branch: master
- type: git
  repo: https://git.coding.net/muasy/muasy.github.io.git
  branch: coding-pages
  message: "Site updated: {{ now('YYYY-MM-DD HH:mm:ss') }}"

写一个 push 脚本

#! /bin/bash

# Author  : SY
# Version : V1.0.0
# Date    : 2017-7-16 10:43:18
# brief   : Auto Sync To GitHub

git add -A

echo "----------------------------------------"
echo "Input Message:"
read MESSAGE
if [ -z $MESSAGE ];
then
    MESSAGE="update"
fi
time="`date +%F` `date +%T`"

_COMMIT="[$time]<$MESSAGE>"
echo $_COMMIT

echo "----------------------------------------"
git commit -m "[$time]<$MESSAGE>"

git push

echo "----------------------------------------"
echo "Done!"

写一个 deploy 脚本

#! /bin/bash

# Author  : SY
# Version : V1.0.0
# Date    : 2017-7-16 10:43:18
# brief   : Auto Deploy To GitHub

echo "----------------------------------------"
hexo clean
hexo g
cp CNAME ./public
echo "deploy..."
hexo deploy

echo "----------------------------------------"
echo "sync..."
./push.sh

echo "----------------------------------------"
echo "Done!"

执行脚本,自动部署线上博客

./deploy.sh

查看效果:浏览器输入 dasuimao.com

Hexo常用命令

hexo clean:清楚缓存文件,如果遇到修改文件不能正常显示时,执行!

hexo g:生成静态网站,在Hexo/public目录

hexo s:启动本地服务器,之后就可以使用localhost:4000访问了。

hexo deploy:部署到在线的网站上,就可以使用手机或者电脑查看了。

hexo new "new blog name":新建blog

参考

通过hexo-deployer-rsync部署Hexo博客到VPS主机

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值