使用hexo和github搭建个人博客

使用hexo和github搭建个人博客

准备工作

  1. 安装git bash

  2. 安装nodejs:官网

  3. 安装hexo:npm i hexo-cli -g

hexo常用命令

官网文档:https://hexo.io/docs/commands

建立网站

1
hexo init

新建文章

使用该命令后,会在source/_posts/目录下建立title.md文件

1
hexo new <title>

启动hexo服务

1
hexo server

生成静态文件

1
hexo generate

部署网站

1
hexo deploy

清除文件

使用改名会清理缓存文件 (db.json) 和已生成的静态文件 (public)

1
hexo clean

搭建个人博客

本地搭建blog

  1. 在本地初始化博客项目

    1
    2
    3
    4
    cd /d/workspace		# 进入一个工作目录
    hexo init blog # 初始化blog
    cd blog
    npm install # 安装依赖
  2. 设置博客标题和博主:打开配置文件_config.yml ,找到下面配置

    1
    2
    3
    4
    5
    6
    7
    # Site
    title: tcbaby's blog
    subtitle: ''
    description: ''
    keywords:
    author: tcbaby
    language: en
  3. 使用hexo server命令,启动博客项目。访问http://localhost:4000/即可看到我们的博客。

GitHub Page

  1. 在GitHub上创建一个用户名.github.io的仓库

  2. _config.yml文件中指定仓库地址

    1
    2
    3
    4
    5
    6
    # Deployment
    ## Docs: https://hexo.io/docs/deployment.html
    deploy:
    type: git
    repo: git@github.com:tcbaby/tcbaby.github.io.git
    branch: master
  3. 生成静态文件并推送到GitHub仓库

    1
    hexo g && hexo d
  4. 访问https://用户名.github.io即可。

其它配置

更换主题

官网主题:https://hexo.io/themes/
icarus主题:文档
选择好自己喜欢的主题后,下载到themes目录下,修改_config.yml配置文件中theme

1
theme: icarus

访问统计插件

访问统计:http://ibruce.info/2015/04/04/busuanzi/

1
2
3
4
5
6
7
8
9
10
11
<!-- 网站访问量 -->
<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<p style="font-size:12px; color: burlywood">
本站总访问量:<span id="busuanzi_value_site_pv"></span>
本站访客数:<span id="busuanzi_value_site_uv"></span>
</p>
<!-- 文章阅读量 -->
<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<span id="busuanzi_container_page_pv">
本文总阅读量<span id="busuanzi_value_page_pv"></span>次
</span>

 

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×