开始搭建-hexo-git-blog

目录

从git起,使用hexo搭建自己的博客,git上传各种资料方便快捷,基于win7系统搭建。

安装软件

1,安装git,确保在cmd下可以git –version出版本,关键配置好环境变量,这时git下会有三个终端,
Git Bash,Git CMD,Git GUI,后续命令均在Git Bash下输入。

2,安装hexo,到官网下载自己合适的版本,安装方式根据官网例子。

配置

1,在github上注册自己的账号,会得到一个用户名(yourname);
2,新建repository,把名字取为yourname.github.io,注意这里的yourname与注册的git账号用户名必须保持一致;
3,这时在你的git下会有有一个子目录,yourname.github.io,点击进去,查看setting,在GitHub Pages那块会出现site,不用急;

命令行搭建

1
2
3
4
5
6
7
8
1,在自己本地机器上新建一个目录,dir
2,Git Bash进入终端,然后cd进入该目录,然后输入:
2.1 hexo init
2.2 npm install (时间有点久,等待各种依赖包下载完成)
2.3 hexo g
2.4 hexo s
3,在本地机器上输入网址http://0.0.0.0:4000/,将看到默认的网页,即你的博客样子,当然后续可以自定义修改板式。
注意,如果4000端口被占用,即连接不能打开,则换用指定端口,hexo s -p 3600.

构建自己的博客

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
1,修改默认的格式,在dir目录下,有个_config.yml,修改#site下的内容
2,在#URL下添加如下内容
url: https://chlyzzo.github.io/
root: /
permalink: :year/:month/:day/:title/
permalink_defaults:

3,在#deployment下增加内容
deploy:
type: git
repository: [email protected]:yourname/yourname.github.io.git
branch: master
4,进入到dir目录
4.1 运行命令npm install hexo-deployer-git --save
4.2 运行命令hexo d -g
4.3 在网页输入网址https://yourname.github.io/,即查看到自己的博客样式。

5,主题修改,在 _config.yml中的theme参数,而主题文件存放位置dir/themes目录下,
theme: jacman

6,错误解决
6.1 ERROR Deployer not found: git
运行 npm install hexo-deployer-git --save
6.2 查看ssh-key的状态ssh -T [email protected]
6.3 重新生成ssh-key
git config --global user.name "John Doe"
git config --global user.email [email protected]
ssh-keygen -t rsa -b 4096 -C "[email protected]"

主题挑选

可以在很多开源github上找到主题,然后自己修改下适合自己的。下载主题然后存放到themes下,并在dir目录下的_config.yml文件中修改主题路径。

您所看到的博客主题是经作者自己修改的jacman主题,需要下载的朋友可以从chlyzzo-jacman下载,然后修改参数和数据,得到属于自己的博客。

根据样式效果调整,可以在页面改动html参数,然后在主题的layout等下找出对应的页面位置,进行修正或增删。

阅读数量统计

1
2
3
4
5
6
7
8
放置在自己认为合适的位置,
<script async src="//dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<p class="article-count">
<count itemprop="visitors">阅读量: <span id="busuanzi_value_page_pv"></span> </count>
</p>
<p class="article-count">
<count itemprop="visitors">阅读量: <span id="busuanzi_value_page_uv"></span> </count>
</p>

新增文章

1,命令格式,hexo new post “文章的名字”,

2,在dir目录的source/_posts下自定义filename.md,有固定格式,

3,板式在dir目录的thems下修改,

4,git 需要ssh key,这个可以参考安装方法,

5,涉及到中文,最好把文件转为utf格式,不然显示乱码,建议使用Atom软件编辑。

域名

上述的博客地址是https://chlyzzo.github.io/形式,如果想变成自己的独特域名,像作者用的是www.chloy.com,那么需要经如下步骤调整:

  • 1,购买域名,可以在阿里云上购买,或者其他途径购买;
  • 2,在github上配置域名,找到yourname.github.io的github目录,在settings的custom domain中填写购买的域名的,然后保存;
  • 3,域名解析,在域名控制台添加如下两个解析路径:
记录类型 主机记录 解析线路 记录值 MX优先级 TTL值
A @ 默认 151.101.73.147 10分钟
CNAME www 默认 chlyzzo.github.io 10 分钟
  • 4,在dir/source/目录下添加一个文件,名字为CNAME,内容为购买的域名。

原文:大专栏  开始搭建-hexo-git-blog


猜你喜欢

转载自www.cnblogs.com/wangziqiang123/p/11652275.html
今日推荐