Github+Hexo搭建静态Blog自学教程


Hexo

是基于Node.js的静态Blog搭建工具,结合

Github

Pages功能,能够建立一个自主管理的独立博客。下面介绍我是如何建立出这个网站的。

参考文章:

如何搭建一个独立博客——简明Github Pages与Hexo教程

首先先下载安装node.js,Git。


1 首先在本地建立并运行静态blog###

建立一个文件夹,如 H:\Hexo在win文件夹窗口右击,点击git bash。之后操作推荐全部用命令行。

$ npm install -g hexo       #安装Hexo

$ hexo init                    #在H:\Hexo 文件夹生成blog模板

$ hexo g                    #生成静态blog == hexo generate

$ hexo s                    #在本地运行服务器 == hexo server

就可以看到初始的静态Blog:Helloworld

如果想要写一篇以“new_post_name”为名的新文章,则输入

$ hexo n "new_post_name"

会在\source\_posts下生成new_post_name.md的Markdown文件,编辑此文件写文章。
当然可以直接在\source\_posts新建*.md文件

重新运行:

$ hexo g

$ hexo s

就可以看到新加文章

2 将建立的静态Blog push到Github上去###

首先你得有一个Github账户,申请过程忽略

其次在本地配置SSH 公钥

如果邮件地址是[email protected]

生成新的SSH Key:

$ ssh-keygen -t rsa -C "[email protected]"

Generating public/private rsa key pair.

Enter file in which to save the key (/Users/your_user_directory/.ssh/id_rsa):

直接回车,

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

输入密码,生成SSH Key

  • 将SSH 公钥输入Github网站

打开 /Users/your_user_directory/.ssh/id_rsa.pub

将里面的密钥复制

打开Github网站,登陆,进入Account Settings--->SSH Public keys ---> add another public keys,点击add key,将复制的密钥粘贴进去

可以通过 ssh -T git@githubcom看看设置是否成功

    The authenticity of host 'github.com (207.97.227.239)' can't be established.

    RSA key fingerprint is 6:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.

    Are you sure you want to continue connecting (yes/no)?yes

    Hi ! You've successfully authenticated, but GitHub does not provide shell access.

还需要配置用户名,邮箱

    $ git config --global user.name "yourname"

    $ git config --global user.email  "[email protected]"

目前本地git配置完成。

接着,需要在Github网站上建立一个项目Repository。

Github上只有Pages项目才能输出为Html。我们可以把pages放在一个项目中,也可以新建一个

yourname.github.io

的项目,分支选择ph-pages,访问yourname.github.io就可以。
我们点击New Repository,新建一个代码仓库,我的名称就写jcjview.github.io

在setting里选择

SSH URL

(当然也可以用HTTPS,但这样配置的SSH密钥就白配置了)

复制出来,

[email protected]:yourname/yourname.github.io.git


我的就是[email protected]:jcjview/jcjview.github.io.git

将项目的branch添加一个ph-pages,这样访问

yourname.github.io

才能显示网页

在hexo文件夹根目录下,打开_config.yml文件,修改最后的deploy字段:

deploy:

type: github

repository: [email protected]:yourname/yourname.github.io.git

branch: master

配置好后,就可以上传了

$ hexo d         # hexo deploy

3 修改主题###

默认的主题比较单调,而且没有sitemap,评论等功能,需要修改主题文件来添加。

(待续)

4 购买配置域名###

(待续)

你可能感兴趣的:(Github+Hexo搭建静态Blog自学教程)