hexo 故障解决方案
webpack
编译
cd themes/yilia
<!-- 编译项目,此外只要看到没报错,卡在最后即可,它是实时打包刷新的,并不是出错了 -->
npm run dist
node-sass
原版 node-sass
<!-- 如果还是用原版的package-json里面的[email protected]版本,会和node的高版本报错,比如node12等,不想报错的话,需要更新node-sass版本 -->
npm install node-sass@latest --save-dev
升级 webpack4.0
如果需要升级 webpack4or5 的,最好还是换成 dart-sass 把,省的解决一堆烦心事= - =
需求 Python2 的环境
需要配置 Python2 的环境变量,可以通过python
拉起 Python2 的程序,坑
看板娘
点关闭后不再显示
由于本地 cookie 里面存储了变量是不展示,导致怎么刷新都不出来= - = ,需要清理游览器缓存才可以,颓了 o(╥﹏╥)o
npm/yarn 缓慢
推荐转为使用 yarn,安装完后在根目录下执行 yarn install 即可,一般这样就执行成功了。
切换国内源
- 方法
- 1️⃣ 手动配置切换,比如说通过根目录下配置
.yarnrc
文件,放入以下的配置内容 - 2️⃣ 通过
nrm ls
+nrm use taobao
进行切换源,需要安装 nrm [npm install -g nrm
] ,此外如果是 windows 用户请参考下面的方法进行修改^nrm
- 1️⃣ 手动配置切换,比如说通过根目录下配置
registry="https://registry.npm.taobao.org"
sass_binary_site="https://npm.taobao.org/mirrors/node-sass/"
phantomjs_cdnurl="http://cnpmjs.org/downloads"
electron_mirror="https://npm.taobao.org/mirrors/electron/"
sqlite3_binary_host_mirror="https://foxgis.oss-cn-shanghai.aliyuncs.com/"
profiler_binary_host_mirror="https://npm.taobao.org/mirrors/node-inspector/"
chromedriver_cdnurl="https://cdn.npm.taobao.org/dist/chromedriver"
墙的问题
有一些资源会去请求 github.com 等,哪怕你改了镜像源,假如网络环境不好,那编译就一直失败了,这里强烈推荐 switch-hosts github 地址
然后附赠一份 github hosts 自动更新的网址 https://cdn.jsdelivr.net/gh/ineo6/hosts/hosts
BUG
Bug1: yarn 无法安装 hexo-deployer-git
使用yarn global add hexo-deployer-git
当然这样就导致没办法指定版本了,或者可以选择再次切换回去。
Bug2: hexo command not found
yarn global add hexo-cli
npm install hexo-cli --save -g
重点在于全局安装
BUG3: 资源构建错误
yarn add --force
# or npm的
npm rebuild
备份/编译
以下的方案以及@deprecated,现在是通过 github action+提交源码的方式实现,无需在从两个 git 源来回切换了,现在就是直接提交源码即可,交由 github 进行编译
action
# 在博客根目录下创建.github/workflows/deploy.yml文件
name: CI
on:
push:
branches:
- master
env:
GIT_USER: tyrantqiao
GIT_EMAIL: [email protected]
THEME_REPO: tyrantqiao/源代码目录项目
THEME_BRANCH: master
DEPLOY_REPO: tyrantqiao/推送代码项目即githubPage的项目
DEPLOY_BRANCH: master
jobs:
build:
name: Build on node ${{ matrix.node_version }} and ${{ matrix.os }}
runs-on: ubuntu-latest
strategy:
matrix:
os: [ubuntu-latest]
node_version: [12.x]
steps:
- name: Checkout
uses: actions/checkout@v2
# - name: Checkout theme repo
# uses: actions/checkout@v2
# with:
# repository: ${{ env.THEME_REPO }}
# ref: ${{ env.THEME_BRANCH }}
# path: themes/yilia
- name: Checkout deploy repo
uses: actions/checkout@v2
with:
repository: ${{ env.DEPLOY_REPO }}
ref: ${{ env.DEPLOY_BRANCH }}
path: .deploy_git
- name: Use Node.js ${{ matrix.node_version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node_version }}
- name: Configuration environment
env:
# 在仓库下的Settings->Secrets->New Repository secret新建secrets,把密钥放进去
HEXO_DEPLOY_PRI: ${{secrets.HEXO_DEPLOY_PRI}}
run: |
sudo timedatectl set-timezone "Asia/Shanghai"
mkdir -p ~/.ssh/
echo "$HEXO_DEPLOY_PRI" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan github.com >> ~/.ssh/known_hosts
git config --global user.name "tyrantqiao"
git config --global user.email "[email protected]"
cp _config.theme.yml themes/yilia/_config.yml
- name: Install dependencies
run: |
npm i -g hexo-cli
npm install gulp -g
npm i
- name: 部署博客
run: |
rm -rf .deploy_git
hexo g
gulp
hexo deploy
rm ~/.ssh/id_rsa
配置完后,就是推送代码,让 github 进行编译推送即可,另外如果有需要国内访问的,可以找多一个 github Page 的镜像源,让它拉取你的 github Page 的项目,也生成一份博客页面。
在 DNS 处配置下 githubPages 以及国内镜像源,方便两边都可以展示
~~~希望备份博客,下载回来后无法安装~~~
这里使用的是知乎张钊的方法
知乎链接
deploy:
- type: git
repo: [email protected]:xxx/xxx.github.io.git
branch: master
- type: git
repo: [email protected]:xxx/xxx.github.io.git
branch: src
message: commit message
extend_dirs: /
ignore_hidden: false
ignore_pattern:
public: .
当 deploy 时会发现 xxxgit 失败,因为.deploy_git 下会有部分文件无法覆盖提交= V =这就只能删掉.deploy_git 才重新 deploy 了。目前没找到其他解决方案,欢迎提供。
备份恢复
当拉了备份文件时,记得要下载 nodejs 新版本以及在根目录下执行npm install
或者yarn install
安装依赖。
// I:\Program Files\nodejs\node_global\node_modules\nrm\cli.js 文件路径
//const NRMRC = path.join(process.env.HOME, '.nrmrc');(注掉第17行),修改后将可以正常执行,不修改的话,会报错
const NRMRC = path.join(
process.env[process.platform == "win32" ? "USERPROFILE" : "HOME"],
".nrmrc"
);
打包编译测试
开发 执行npm run dev 此时会用webpack打包,把文件编译到source文件里,但文件不会经过压缩
发布 执行npm run dist 最终确定版本,此时的编译会经过压缩。