github第一篇博文:搭建独立博客GitHub Pages与Hexo的步骤

搭建独立博客GitHub Pages与Hexo的教程
1.需要安装node.js, git,
2.需要有github的户头, 并建立一个public的repo,名字为:用户名.github.io,在github上该仓库显示为:
用户名/用户名.github.io
如此命名的repo下面设置后可以用 “http://用户名.github.io” 访问。

3.配置SSH keys
SSH安全通信用于本地git项目与远程的github建立联系

a)生成新的SSH key:(往下的命令都是在git cmd 命令窗口,除非特别说明)

ssh-keygen -t rsa -C “youremail@addr”
然后一路按回车
这会在用户主目录生成一对文件.\ssh\id_rsa 和 id_rsa.pub

b)本地设置SSH Key之后,需要在GitHub网站上个人帐号的setting中,添加一个新key
登录GitHub,点击右上角的 Settings–>SSH & Public keys–> add keys
打开本地~.ssh\id_rsa.pub文件把你本地生成的钥匙文本全部复制到里面,然后点击add key

c)检验fingerprint,与网站的sha256一致(可选)

ssh-keygen -E sha256 -lf id_rsa.pub

4.设置用户信息
Git会根据用户的名字和邮箱来记录提交到github,所以需要设置下个人信息

git config –global user.name “xxxx”//用户名
git config –global user.email “xxx@gmail.com“//填写自己的邮箱

5.用hexo制作博客
安装hexo(可参考最新官网

npm install -g hexo
建立一个新的工作文件夹来放hexo生成的项目文件,然后在文件夹中输入
hexo init
hexo 命令
n:新博客页 g:转换生成 s:启动预览服务器 d:发布到github

hexo n “newfile”即可生成新的md文件,位于source_posts之中。
删除相应的md文件就可以删除博客页

6.博客内容修饰和markdown
Markdown 语法说明(简体中文版)

7.用hexo发布到github(要靠_config.yml的deploy设定目的)
deploy:
type: git
repository: git@github.com:用户名/用户名.github.io.git
branch: master
命令:
hexo d
如果有ERROR Deployer not found: git 则要多装一个packet:
npm install hexo-deployer-git -save
如果hexo d有warning:
The authenticity of host ‘github.com (140.82.112.4)’ can’t be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no/[fingerprint])?
用yes继续即可。