# 0. 序

本文整理了博主使用 Hexo 框架在 Windows 平台搭建博客的过程,同时收集了部分搭建过程可能出现的错误。其中各步骤可能出现的报错内容及相应解决办法均被集中列在文章最后一节,在可能会报错的操作后会以 ""作为标记。点击标记即可跳转至文章最后一节相应位置,这一节部分后续或许会更新。文章参考的内容可在最后" 参考内容 " 部分查看.

# 1. 工具安装及环境部署

本文中,搭建博客需要的工具包括: Node.js、Git、Chocolatey (Node.js 安装附带)、npm (Node.js 安装附带)、Python (Node.js 安装附带) 与 cnpm (代替 npm 加快下载).

# 安装部署 Git 环境

  1. 从 Git 官网下载 Git-for-Windows

  2. 配置 Git 环境 (配置方法详见 "Windows for Git 安装与配置")

# 安装 Node.js 及相关工具

# 1. 下载 Node.js

  • 从 Node.js 官网下载 Node.js LTS 版本.

  • 或选择下载其他版本.

# 2. 安装 Node.js

双击打开下载的 msi 安装文件,选择安装路径,然后在 "Tools for Native Modules" 页面勾选 "Atuomatically install the necessary tools." 选项,安装完成后会弹出 CMD 窗口并自动安装所需要的工具 (Chocolatey、Python 与 Vitural Studio 2019 工具).
其中,由于是国外网站,Python 的安装速度较慢,

检验是否安装完成:

1
2
3
4
# 查看Node.js版本
node -v
# 查看npm版本
npm -v
  1. 利用 npm 安装 cnpm 加快国内安装
1
2
3
npm install -g cnpm --registry=https://registry.npm.taobao.org
# 检验cnpm安装是否成功
cnpm -v
  1. 安装 Hexo
1
2
3
cnpm install -g hexo-cli
# 检验是否安装完成
hexo -v

# 开始

新建一个文件夹来存放博客文件,直接删除博客文件夹即可删除整个博客.

1
2
3
4
# 在命令行中
mkdir 博客文件夹名称
# 在PowerShell中
New-Item -Path X:/xxx/xxx/ -Name 博客文件夹名称 -ItemType directory

# Step 3. 本地预览

一般来说,一篇博客在部署到网站之前都需要经过多次预览与修改,这意味着我们要在本地上多次预览博客并根据根据预览情况进行调整,而 Hexo 正好提供了此功能,要在本地预览博客,只需要在终端输入如下命令:

1
2
# 启动博客, s时命令server的简写
hexo s

此时如果弹出 Windows 安全中心警报选择允许访问即可.

# Step 4. 云端同步

当我们在本地的博客 / 网站调整得差不多后,就要考虑将

# 报错处理

  • Error: error_name
  • Reason & Solution
    One of Reasons is xxx. The solution is to xxx.

  • 报错内容:

1
2
python not installed. An error occurred during installation:  
操作超时
`python package files upgrade failed with exit code 1. Performing other installation steps.`
1
2
3
The upgrade of python was NOT successful.
python not installed. An error occurred during installation:
操作超时