github+hexo搭建博客

2017-12-12  本文已影响11人  依然饭太稀

Install

安装nvm(Node Version Manager),Terminal中运行

$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.7/install.sh | bash

会提示:

=> Close and reopen your terminal to start using NVM

退出Terminal重启后nvm命令才能生效。

假如update失败,可能没有profile文件,touch一下:

$ touch ~/.bash_profile

$ touch ~/.profile

使用nvm安装node.js:

$ nvm install 9.2.1

下完后安装hexo,这一步时间比较长:

$ npm install -g hexo

然后找个文件初始化blog:

$ cd ~/git/blog

$ hexo init .

$ ls

[update]更新hexo2.6版本后安装还需要执行:

$ npm install hexo-renderer-ejs --save

$ npm install hexo-renderer-stylus --save

$ npm install hexo-renderer-marked --save

$ npm install hexo-deployer-git --save

生成出的目录结构:

.

├── _config.yml

├── package.json

├── scaffolds

├── scripts

├── source

|  ├── _drafts

|  └── _posts

└── themes

新建一篇文章:

$ hexo new mac下使用hexo搭建blog

$ open source/_posts/mac下使用hexo搭建blog.md

编辑md后生成html:

$ hexo generate

本地预览:

$ hexo server

=> [info] Hexo is running at localhost:4000/. Press Ctrl+C to stop.

Theme,去官方提供的主题列表中选个现成的,按照里面的方法pull下来,如light主题

$ git clone git://github.com/tommy351/hexo-theme-light.git themes/light

_config.yml配置文件中设置:

theme: light

重新generate和server预览,就看到变化了。

Deploy

github上建个respository,设置里设一下

在_config.yml中:

deploy:

type:git

repository:https://github.com/EriconYu/eric-blog.git

然后执行:

$ hexo deploy

就行了,github会多一个branch,比octopress简单

绑定域名

去万网买了这个域名stackbang.com,以stackbang.com作为博客的域名,

看万网是阿里的才从那儿买的,后来发现DNSPod貌似比较好,万网的后台做的那叫一个*,但愿解析速度上别再不行就行。

托管在github上,首先建一个CNAME文件,里面写最终指向的域名:

$ stackbang.com > public/CNAME

然后去域名后台配置下,由于github表示说我托管的页面的域名是:EriconYu.github.io

所以建一个CNAME记录,将stackbang.com解析到EriconYu.github.io

DNS域名解析最常用的是A记录CNAME记录,A记录把域名解析到服务器IP,CNAME相当于把一个域名指向另一个域名,因此我这个用的是CNAME,要是托管的服务器也是自己搭的那就用A记录了。

完事之后得等一段时间(DNSPod说几秒内就同步完,要是这样真心是它好)

使用下面的命令测一下域名的解析

$ dig stackbang.com +nostats +nocomments +nocmd

=> output:

;; global options: +cmd

;blog.sunnyxx.com.      IN  A

blog.sunnyxx.com.  1778    IN  CNAME  EriconYu.github.io.

sunnyxx.github.io.  1778    IN  CNAME  github.map.fastly.net.

github.map.fastly.net.  30  IN  A  103.245.222.133

这说明是成功了,发现解析过程是stackbang.com->EriconYu.github.io->github.map.fastly.net->103.245.222.133最终指向了github的web server

由于国内GreatWall,解析速度明显不稳定,有时候都连不上,以后再看怎么办吧

添加Sitemap

同样的,我们使用hexo提供的插件,方法与添加RSS类似。

安装sitemap到本地:

npm install hexo-generator-sitemap

开启sitemap功能:编辑hexo/_config.yml,添加如下代码:

plugins:

- hexo-generator-sitemap

访问zipperary/sitemap.xml即可看到站点地图。不过,sitemap的初衷是给搜索引擎看的,为了提高搜索引擎对自己站点的收录效果,我们最好手动到google和百度等搜索引擎提交sitemap.xml。

添加友情链接

themes/xxxxxx/layout/_widget/blogroll.ejs

友情链接

稀饭同学的博客

上一篇 下一篇

猜你喜欢

热点阅读