官方

https://hexo.io/zh-cn/

说明

搭建自己博客分为两类,一种是托管到 github 上的,以 hexo 为代表,另一种是需要自己购买服务器,主要使用 wordpress、帝国 cms、织梦 cms 等框架。下面介绍下使用 hexo 搭建个人博客。

配置环境

  1. 安装 git
  2. 安装 nodejs
  3. 安装 hexo

npm install hexo-cli -g

注意:npm 安装报错 code Z_BUF_ERROR errno -5 ! zlib: unexpected end of file

解决办法地址: https://cnodejs.org/topic/4f9904f9407edba21468f31e

1
2
3
4
5
6
7
8
9
10
11
12
13
镜像使用方法(三种办法任意一种):

1.通过 config 命令更换国内镜像
npm config set registry https://registry.npm.taobao.org
npm info underscore (如果上面配置正确这个命令会有字符串response)

2.命令行指定
npm --registry https://registry.npm.taobao.org info underscore

3.编辑 ~/.npmrc 加入下面内容
registry = https://registry.npm.taobao.org

淘宝 NPM 镜像: https://npm.taobao.org

创建博客站点,发布文章,本地浏览

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 创建博客站点、初始化、安装依赖
mkdir blog
cd blog
hexo init
npm install

# 启动博客
hexo s

# 浏览器里访问
http://localhost:4000

# 创建标签、分类、关于页面
hexo new page "tags"
hexo new page "categories"
hexo new page "about"

# 创建博客文章
hexo new "建立个人博客"

# 生成静态页面
hexo g

浏览器里访问
UTOOLS1576650681105.jpeg

发布到 GitHub

  1. github 上创建仓库
    UTOOLS1576650686006.jpeg
  2. 修改根目录下的 _config.yml 中 deploy 项
deploy:
  type: git
  repo: https://github.com/xxx/yyy.git
  branch: main
  message: "update"
  1. 安装 hexo 的 deployer 插件

    npm install hexo-deployer-git –save

  2. 发布博客到 github 上

    hexo d

  3. 浏览器访问地址:https://wangwenzhe.github.io

自定义设置

butterfly 主题