Github pages + Hexo 搭建个人博客

2018-09-18  本文已影响22人  我脱下短袖

安装

准备环境(NodeJS+Git)

安装Hexo

hexo init Blog
cd Blog
cnpm install
hexo server

安装主题

我选的是NexT

hexo clean
git clone git@github.com:theme-next/hexo-theme-next.git themes/next

在项目根目录下面修改_config.yml配置文件中的theme属性,将其设置为next

hexo generate
hexo server

现在打开http://localhost:4000/ ,会看到我们已经应用了一个新的主题

hexo generate 可以简写为 hexo g

hexo server 可以间写为 hexo s

hexo deloper 可以简写为 hexo d

Github Pages设置

注册Github账号,创建repository,比如我创建 zoukeqing.github.io,不要勾选README.md文件

域名

域名购买

我是从阿里云购买 zoukeqing.top ,当然你通过其它渠道购买也可以,只要能域名解析就行

Ping 域名

![ping](https://img.haomeiwen.com/i3525784/f0e3c0f86ab95581.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

域名解析

解析

新建CNAME文件

\themes\next\source 目录下新建CNAME文件,无后缀名,加上自己的域名就可以,比如 zoukeqing.top

hexo deploy部署

在项目根目录下配置文件_config.xml中作如下修改:

# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
  type: git
  repo: git@github.com:zoukeqing/zoukeqing.github.io.git
  branch: master

提前安装一个扩展,用于hexo deloper 命令提交到Github项目中

npm install hexo-deployer-git --save

然后在命令 hexo d执行完成部署,打开Github项目文件就可看到提交上来的静态文件

MarkDown写作

new

MarkDown编辑器

[Typora](https://typora.io/#)   

[HexoEditor](https://github.com/zhuzhuyule/HexoEditor)

访问量和文章阅读量

主题配置

LeanCloud

为什么要用LeanCloud是因为不蒜子存在一个缺点是,不能在首页直接看单篇文章的阅读量

设置安全域名

不设置安全域名是看不到数字的,同时也将本地 http://localhost:4000 也添加进去,方便本地调试

image

本地搜索

# Local search
# Dependencies: https://github.com/flashlab/hexo-generator-search
local_search:
  # enable: false
  enable: true
  # if auto, trigger search by changing input
  # if manual, trigger search by pressing enter key or search button
  trigger: auto
  # show top n results per article, show all results by setting to -1
  top_n_per_article: 1
search:
  path: search.xml
  field: post
  format: html
  limit: 1000

设置动态背景

在主题配置文件中找到canvas_nest,设置成ture

添加RSS

plugins: hexo-generate-feed
# Set rss to false to disable feed link.
# Leave rss as empty to use site's feed link.
# Set rss to specific value if you have burned your feed already.
rss: /atom.xml

社交链接

在主题目录下配置 _config.yml 添加如下

# Social Links
# Key is the link label showing to end users.
# Value is the target link (E.g. GitHub: https://github.com/iissnan)
#social:
  #LinkLabel: Link
social:
  GitHub: https://github.com/halzhan
  Twitter: https://twitter.com/zoukeqing
  E-Mail: gmailto:zoukeqing@gmail.com or qqto:1146704412@qq.com

最后的效果

image
上一篇下一篇

猜你喜欢

热点阅读