Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hexo 搭建博客问题 #17

Open
richardmyu opened this issue Jan 1, 2021 · 10 comments
Open

Hexo 搭建博客问题 #17

richardmyu opened this issue Jan 1, 2021 · 10 comments
Labels
Projects

Comments

@richardmyu
Copy link
Owner

richardmyu commented Jan 1, 2021

1.gulp 安装更新

执行 hexo g 之后生成的代码,结构比较乱,空格空行都很多,使用 gulp 进行压缩,以获取更快的加载速度。

旧版本 HEXO 的安装:

npm install -g gulp

新版本 HEXO(5.x) 安装:

npm install gulp-cli -g
npm install gulp -D

越来越多的人认同的一个共识是:最好不要全局安装项目所需要的依赖。 这主要是由于这些依赖不会显示在项目的依赖项列表中,如果要共享代码,则意味着您需要明确声明您的项目具有的依赖项超出了依赖文件本身。使问题更加复杂的是,您可能将项目搁置一段时间,然后将全局软件包安装更新为与项目中使用的版本不兼容的某个新版本,从而在重新访问该项目时引起冲突。据我了解,gulp-cli 直接解决了这些问题,因为它允许您通过提供 shell 访问来运行 gulp 的本地安装,就好像它是全局安装一样。 Gulp global install - gulp vs gulp-cli

what does gulp-“cli” stands for?

语法问题

注意 gulp 语法(对于 4.x 版本而言)已经更新的问题:

旧版本:

//JS压缩
gulp.task('uglify', function() {
  return gulp.src('./public/**/*.js')
    .pipe(uglify())
    .pipe(gulp.dest('./public'));
});

新版本(4.0.2)语法:

function miniJs() {
  return pipeline(
    src('./public/**/*.js'),
    uglify(),
    dest('./public')
  );
}

这一部分,可能随着时间推移,这里说的也会有问题,总之记得去官网看语法。


2.图片模块安装更新

npm install gulp-htmlclean gulp-htmlmin gulp-minify-css gulp-uglify gulp-imagemin --save

这些都是开发依赖,应该放到 devDependencies 中去:

npm install gulp-htmlclean gulp-htmlmin gulp-minify-css gulp-imagemin --save-dev
# or
npm install gulp-htmlclean gulp-htmlmin gulp-minify-css gulp-imagemin -D

注意,我把其中的 gulp-uglify 拿出来没有安装,是因为如果压缩的 JavaScript 代码涉及到某些 ES6 语法时,会因语法问题而无法成功压缩,可以使用 gulp-uglify-es 解决这个问题。

gulp-uglify 的问题可以见 gulp 压缩之 gulp-uglify #16


3.gulp-imagemin 模块部分规则更新

jpegtran 没有了,需要用 mozjpeg 代替。

同样也是因为版本更新,部分参数或方法以发生变化,总之,若有问题,先参考官网。更多细节


4.图片

1.使用 PS 压缩图片;
2.使用图床或 CDN 来加载图片,而不是放在博客自身目录下(主要就是 Github 访问慢...);
3.我选择的 Next 主题有内置的图片懒加载,修改即可;


5.锚点失效

不确定是不是更换了 hexo-renderer-markdown-it 造成的问题,只记得一开始锚点有效的,后来偶然发现锚点失效了,经查看页面源码,发现是标题渲染没有 id 属性。

在阅读 Hexo 博客踩坑 一文后,增加对这个问题的认识。基于 Less is More 的原则,决定不采用增添插件,修改源码的方式了。既然渲染引擎没法正常给标题的添加 id 属性,咱们自己手动给它加上不就好了吗:stuck_out_tongue_winking_eye:?

### 1.引言

// 看,相对于来增加插件来说,这样不是更简单
<h3 id="引言">1.引言</h3>
@richardmyu richardmyu added the Tool gulp,webpack... label Jan 1, 2021
@richardmyu richardmyu changed the title Hexo 优化部分笔记 Hexo 搭建博客问题 Jan 24, 2021
@richardmyu richardmyu changed the title Hexo 搭建博客问题 Hexo 搭建博客问题 (WIN10) Mar 2, 2021
@richardmyu
Copy link
Owner Author

richardmyu commented Mar 31, 2021

6.Spawn failed

今天更新了一下相册,最后推送的时候,爆出了这个问题:

Connection reset by xxx.xxx.xxx.xxx port 22
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
FATAL {
  err: Error: Spawn failed
      at ChildProcess.<anonymous> (D:\xx\...\node_modules\hexo-deployer-git\node_modules\hexo-util\lib\spawn.js:51:21)
      at ChildProcess.emit (events.js:210:5)
      at ChildProcess.cp.emit (D:\xx\...\node_modules\cross-spawn\lib\enoent.js:34:29)
      at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12) {
    code: 128
  }
} Something's wrong. Maybe you can find the solution here: %s https://hexo.io/docs   s/troubleshooting.html

之前没见过这类报错,于是就查查 Spawn failed 使什么问题导致的。(虽然不知道具体报错原因,但直觉是网络链接问题,多试几次就好了。。。)

后面试了两次并没有好转,同时也在查这个问题,网页上看到的都是说删除什么什么文件,感觉不靠谱,于是我再试了一次,这一次正常推送了。再反过头看那些回答,基本都只会告诉你怎么解决,但没有一个可以告诉你原因是什么。。。这就很迷!

其实想想,各种 “bug“ 可能会出得奇奇怪怪,但至少还有有一定逻辑因素的。之前正常,突然冒出的问题,在“环境”没有变化的情况下,那大概最大可能就是网络问题了。(同样,在没有查出这个报错问题的我来说,也不一定就是正确的)

@richardmyu
Copy link
Owner Author

richardmyu commented Jun 19, 2021

7.置顶功能

最近想着弄一个文章置顶,然后发现网上的方法还是好几年前,并且 hexo-generator-index 早已更新到 2.0 版本了,估计不靠谱。于是自己去看了看源码:

'use strict';

const pagination = require('hexo-pagination');
const { sort } = require('timsort');

module.exports = function(locals) {  
  const config = this.config;  
  const posts = locals.posts.sort(config.index_generator.order_by);
  sort(posts.data, (a, b) =&gt; (b.sticky || 0) - (a.sticky || 0));
  const paginationDir = config.pagination_dir || 'page';  
  const path = config.index_generator.path || '';

  return pagination(path, posts, {    
    perPage: config.index_generator.per_page,    
    layout: ['index', 'archive'],    
    format: paginationDir + '/%d/',    
    data: {__index: true}});
 };

注意 sort(posts.data, (a, b) =&gt; (b.sticky || 0) - (a.sticky || 0)); 这行代码,感觉是用 sticky 作为置顶的关键字,比数值大小定顺序,若没有指定,则赋值为 0,进行日期比较;同样逻辑,若是 sticky 一样大,也是比较日期。

随便选取两篇文章,第一篇(日期在前)先设 sticky: 1,然后文章置顶,然后选第二篇设置 stickty,预期之内:smile::smile:,同样置顶,且在第一篇前面。

@richardmyu richardmyu changed the title Hexo 搭建博客问题 (WIN10) Hexo 搭建博客问题 Oct 28, 2021
@richardmyu
Copy link
Owner Author

richardmyu commented Oct 28, 2021

8.optipng-bin & gifsicle

在 ubuntu 系统再装博客,安装 hexogulp 过程中,发现了这个问题。

具体:

# ubuntu 20.04.3 LTS x86_64
# node v14.18.1
# npm 6.14.15
# npm config get registry https://registry.npm.taobao.org/


> optipng-bin@6.0.0 postinstall /home/ym/Documents/gitproject/richardmyu.github.io/node_modules/optipng-bin
> node lib/install.js

  ⚠ unable to verify the first certificate
  ⚠ optipng pre-build test failed
  ℹ compiling from source
  ✖ Error: Command failed: /bin/sh -c ./configure --with-system-zlib --prefix="/home/ym/Documents/gitproject/richardmyu.github.io/node_modules/optipng-bin/vendor" --bindir="/home/ym/Documents/gitproject/richardmyu.github.io/node_modules/optipng-bin/vendor"

Checking for gcc...
Using pre-configured libpng...
Checking for system zlib...
./configure: error: missing zlib or incorrect zlib version
./configure: note: zlib version 1.2.1 or higher is required

    at /home/ym/Documents/gitproject/richardmyu.github.io/node_modules/bin-build/node_modules/execa/index.js:231:11
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async Promise.all (index 0)

> gifsicle@5.1.0 postinstall /home/ym/Documents/gitproject/richardmyu.github.io/node_modules/gifsicle
> node lib/install.js

  ⚠ unable to verify the first certificate
  ⚠ gifsicle pre-build test failed
  ℹ compiling from source
  ✖ Error: Command failed: /bin/sh -c autoreconf -ivf
/bin/sh: 1: autoreconf: not found


    at /home/ym/Documents/gitproject/richardmyu.github.io/node_modules/bin-build/node_modules/execa/index.js:231:11
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async Promise.all (index 0)

错误关键词

optpng-binzlibgifsicleautoreconf

错误语句

  • Error: Command failed: /bin/sh -c ./configure --with-system-zlib ...
  • ./configure: error: missing zlib or incorrect zlib version
  • Error: Command failed: /bin/sh -c autoreconf -ivf
  • /bin/sh: 1: autoreconf: not found

其他提示信息

  • unable to verify the first certificate
  • optipng/gifsicle pre-build test failed
  • ./configure: note: zlib version 1.2.1 or higher is required

1.解决 unable to verify the first certificate

造成这个问题,是因为使用了代理。

1.然而在关闭代理后(也清除了 config 内的代理配置信息),依旧没有成功,报如下错:

connect ECONNREFUSED 0.0.0.0:443

2.使用代理,并设置 strict-ssl=false

事实上,我的 npm config 已经设置了 strict-ssl=false,然而并没有解决问题。

2.missing zlib or incorrect zlib version & autoreconf: not found

这两个在系统里确实没有,我们可以试着安装一下,但我觉得不是这个的原因。

# autoreconf -- autoconf
# zlib       -- zlib1g
sudo apt install zlib1g autoconf

不要安装了,因为安装了作用没体现,反而卸载的时候,绑定了许多重要的基础包:

【警告】:下列基础软件包将被卸载。
请勿尝试,除非您确实知道您在做什么!
apt adduser (是由于 apt) gpgv (是由于 apt) libapt-pkg6.0 (是由于 apt) dash dpkg (是由于 dash)
debconf (是由于 dash) zlib1g (是由于 dpkg) grep install-info (是由于 grep) gzip init
systemd-sysv (是由于 init) init-system-helpers (是由于 init) perl-base (是由于 init-system-helpers)
login libpam0g (是由于 login) libpam-runtime (是由于 login) libpam-modules (是由于 login) mount
util-linux (是由于 mount) shim-signed grub-efi-amd64-signed (是由于 shim-signed)
grub2-common (是由于 shim-signed) mokutil (是由于 shim-signed) sbsigntool (是由于 shim-signed)
sysvinit-utils

安装后的结果:

> gifsicle@5.2.1 postinstall /home/ym/Documents/gitProject/richardmyu.github.io/node_modules/gifsicle
> node lib/install.js
    unable to verify the first certificate
    gifsicle pre-build test failed
    compiling from source
    Error: Command failed: /bin/sh -c autoreconf -ivf
    autoreconf: Entering directory `.'
    autoreconf: configure.ac: not using Gettext
    autoreconf: running: aclocal  --output=aclocal.m4t
    Can't exec "aclocal": 没有那个文件或目录 at /usr/share/autoconf/Autom4te/FileUtils.pm line 326.
    autoreconf: failed to run aclocal: No such file or directory


    at /home/ym/Documents/gitProject/richardmyu.github.io/node_modules/bin-build/node_modules/execa/index.js:231:11
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async Promise.all (index 0)

> mozjpeg@6.0.1 postinstall /home/ym/Documents/gitProject/richardmyu.github.io/node_modules/mozjpeg
> node lib/install.js

  ⚠ unable to verify the first certificate
  ⚠ mozjpeg pre-build test failed
  ℹ compiling from source
  ✖ RequestError: unable to verify the first certificate
    at ClientRequest.<anonymous> (/home/ym/Documents/gitProject/richardmyu.github.io/node_modules/got/index.js:111:21)
    at Object.onceWrapper (events.js:520:26)
    at ClientRequest.emit (events.js:400:28)
    at TLSSocket.socketErrorListener (_http_client.js:475:9)
    at TLSSocket.emit (events.js:400:28)
    at emitErrorNT (internal/streams/destroy.js:106:8)
    at emitErrorCloseNT (internal/streams/destroy.js:74:3)
    at processTicksAndRejections (internal/process/task_queues.js:82:21)

> optipng-bin@6.0.0 postinstall /home/ym/Documents/gitProject/richardmyu.github.io/node_modules/optipng-bin
> node lib/install.js

  ⚠ unable to verify the first certificate
  ⚠ optipng pre-build test failed
  ℹ compiling from source
  ✖ Error: Command failed: /bin/sh -c ./configure --with-system-zlib --prefix="/home/ym/Documents/gitProject/richardmyu.github.io/node_modules/optipng-bin/vendor" --bindir="/home/ym/Documents/gitProject/richardmyu.github.io/node_modules/optipng-bin/vendor"

Checking for gcc...
Using pre-configured libpng...
Checking for system zlib...
./configure: error: missing zlib or incorrect zlib version
./configure: note: zlib version 1.2.1 or higher is required

    at /home/ym/Documents/gitProject/richardmyu.github.io/node_modules/bin-build/node_modules/execa/index.js:231:11
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async Promise.all (index 0)
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/glob-watcher/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.3 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: gifsicle@5.2.1 (node_modules/gifsicle):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: gifsicle@5.2.1 postinstall: `node lib/install.js`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: optipng-bin@6.0.0 (node_modules/optipng-bin):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: optipng-bin@6.0.0 postinstall: `node lib/install.js`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1

可以看到,gifsiclemozjpegoptipng-bin 的安装都出了问题,除了 mozjpeg 是证书问题,另外两个基本还是因为 autoreconfzlib


当我准备放弃的时候,又迎来的希望之光。

我升级了 node,到 16.13.0 版本,上述问题都没有了,没有了,没了。。。:smile:,但给了一堆警告:

npm WARN old lockfile 
npm WARN old lockfile The package-lock.json file was created with an old version of npm,
npm WARN old lockfile so supplemental metadata must be fetched from the registry.
npm WARN old lockfile 
npm WARN old lockfile This is a one-time fix-up, please be patient...
npm WARN old lockfile 
npm WARN deprecated gulp-minify-css@1.2.4: Please use gulp-clean-css
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated gulp-util@3.0.8: gulp-util is deprecated - replace it, following the guidelines at https://medium.com/gulpjs/gulp-util-ca3b1f9f9ac5
npm WARN deprecated fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
npm WARN deprecated chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
npm WARN deprecated querystring@0.2.0: The
npm WARN deprecated svgo@1.3.2: This SVGO version is no longer supported. Upgrade to v2.x.x.
npm WARN deprecated highlight.js@9.18.5: Support has ended for 9.x series. Upgrade to @latest

隐藏的问题在一个问题里说明。


3.--ignore-scripts

其实使用参考[4] 的方法(命令后面添加 --ignore-scripts 参数),确实也可以成功安装 optipng-bingifsicle,但不知道有没有其他影响。


更新 21/11/02

重装系统了,于是决定再来试一试,结果没有出现以上的问题,因为出现的其他五花八门的错,甚至:

$ npm install                                    
npm ERR! Unexpected token < in JSON at position 0 while parsing near '<!DOCTYPE html>
npm ERR! <htm...'

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/ym/.npm/_logs/2021-11-02T11_37_54_847Z-debug.log

感觉又回到了 17 年的 npm

你好,我们为你安装了七个包,卸载了十三个包。

更新 21/11/04

没有上面那些乱七八糟的错误了,但是回到这个问题的最初状态,即 gifsicleoptipng-bin 的安装问题。


参考:
1.npm 提示 unable to verify the first certificate 的解决小结 #5
2.npm: unable to verify the first certificate #20949
3.Yarn: unable to verify the first certificate
4.npm install optipng-bin Failed at the optipng-bin@7.0.0 postinstall script

@richardmyu
Copy link
Owner Author

richardmyu commented Oct 30, 2021

9.gulp-imagemin

在上述条件下,安装完成。然后执行 npx hexo cleannpx hexo g,没有什么问题,按照流程,接下来执行 gulp,压缩文件,结果如下:

[22:38:16] Error in plugin "gulp-imagemin"
Message:
    spawn /home/ym/Documents/gitproject/richardmyu.github.io/node_modules/imagemin-optipng/node_modules/optipng-bin/vendor/optipng ENOENT
Details:
    errno: -2
    code: ENOENT
    syscall: spawn /home/ym/Documents/gitproject/richardmyu.github.io/node_modules/imagemin-optipng/node_modules/optipng-bin/vendor/optipng
    path: /home/ym/Documents/gitproject/richardmyu.github.io/node_modules/imagemin-optipng/node_modules/optipng-bin/vendor/optipng
    spawnargs: -strip,all,-clobber,-o,3,-out,/tmp/a9f76343-d171-410a-a397-7c6be5040b24,-fix,/tmp/925435cc-4b38-4220-8d8f-fbc1abef0562
    killed: false
    stdout: 
    stderr: 
    failed: true
    signal: null
    cmd: /home/ym/Documents/gitproject/richardmyu.github.io/node_modules/imagemin-optipng/node_modules/optipng-bin/vendor/optipng -strip all -clobber -o 3 -out /tmp/a9f76343-d171-410a-a397-7c6be5040b24 -fix /tmp/925435cc-4b38-4220-8d8f-fbc1abef0562
    timedOut: false
    fileName: /home/ym/Documents/gitproject/richardmyu.github.io/public/images/apple-touch-icon-next.png
    domainEmitter: [object Object]
    domainThrown: false

查看文件,发现 vendor 下没有 optipng,只有一个 source 目录。所以说升级 node 并没有解决 gulp-imagemin 的问题。

找了一圈,唯一有相同报错的,没有解决方案,只有一个不靠谱的卸载重装。Got ENOENT error with gulp-image

# 有人说用 `cnpm` 可以,我就试了一下,确实可以
npm uninstall --save-dev gulp-imagemin
npm install -g cnpm
# 必须制定 7.1,因为新版本(8.0)改为 ESM
cnpm install --save-dev gulp-imagemin@7.1

安装过程中会提示有很多被废弃的,但现在真不想一个一个去换(有的会提示替代品,有的提示升级,其实升级也有风险,真不知道版本兼任有多少问题;有的就说废弃了,没了。。。:cry:)。


卸载以后使用 cnpm 安装就没有问题。所以,这是为什么呢???:confused::confused::confused: :triumph::triumph::triumph:

为了解决这个问题,使用 meld 检测三种 gulp-imagemin 文件:

1.早期 win10 上安装的 gulp-imagemin -- win-gi;
2.当前时间用 npm 安装的 gulp-imagemin -- npm-gi;
3.当前时间用 cnpm 安装的 gulp-imagemin -- cnpm-gi;

package.json 中,发现当前安装的 json 少了很多描述,并且将 imagemin-gifsicleimagemin-mozjpegimagemin-optipngimagemin-svg 从生产依赖移除,保留在可选依赖(optionsalDependences)中。cnpm-gi 相比 npm-gi,多了:

"__npminstall_done": true,
"_from": "gulp-imagemin@7.1.0",
"_resolved": "https://registry.npmmirror.com/gulp-imagemin/download/gulp-imagemin-7.1.0.tgz"

其他文件基本一致,两份 package.json 均有上述区别。相对 npm-gi 来说,cnpm-gi 多了跟 gulp-iamgemin 相关的包的链接包。具体来说,就是 node_modules 中大部分包,都有对应到版本的以 _package-name@xx@buffer-alloc-unsafe 命名的包。

总之,暂时没有找出 npm 不行而 cnpm 可以的原因。

@richardmyu
Copy link
Owner Author

richardmyu commented Oct 30, 2021

10.Warning: Accessing non-existent property 'xxx' of module exports inside circular dependency

INFO  Start processing
(node:56494) Warning: Accessing non-existent property 'lineno' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)
(node:56494) Warning: Accessing non-existent property 'column' of module exports inside circular dependency
(node:56494) Warning: Accessing non-existent property 'filename' of module exports inside circular dependency
(node:56494) Warning: Accessing non-existent property 'lineno' of module exports inside circular dependency
(node:56494) Warning: Accessing non-existent property 'column' of module exports inside circular dependency
(node:56494) Warning: Accessing non-existent property 'filename' of module exports inside circular dependency

没啥影响,就是看到不舒服。说好了,修复了,结果在高版本还是一样。切换到低版本,可以回避这个问题,但没必要。


1. NodeJS 14 warnings #2534
2. fix: compatible with Node.js 14 #60
3. Fix for Node v14 'Accessing non-existent property' errors #2538

@richardmyu
Copy link
Owner Author

richardmyu commented Nov 4, 2021

11.多端同步

当前 HEXO 博客,实际是单项的,即本地修改上传。而在 github 上,是可以修改博客的 .md 文件的,这样本地就无法获取。多端同步,亦是同样的。在已知博客内容(本地内容经过处理的)是通过 hexo-deployer-git 自动推送的,所以我们还需要一种方法实现本地文件和远程文件的同步。一般有新建远程仓库的,也有通过分支的。

原本我是想用分支的,但看到 hexo 官网--For 使用 Git 管理站点目录的用户,感觉很认可,遂改为新仓库。

@richardmyu
Copy link
Owner Author

richardmyu commented Nov 5, 2021

12.gulp-imagemin 再次出问题

在昨天使用 cnpm 安装 gulp-imagemin,暂时没发现问题,压缩功能正常,今天有不行了:

Error: Can't walk dependency graph: Cannot find module '/home/ym/Documents/gitProject/hexo-source/public/lib/album/gallery.js' from '/home/ym/Documents/gitProject/hexo-source/public/lib/album/_fake.js'
    required by /home/ym/Documents/gitProject/hexo-source/public/lib/album/_fake.js
    at /home/ym/Documents/gitProject/hexo-source/node_modules/_resolve@1.20.0@resolve/lib/async.js:158:35
    at load (/home/ym/Documents/gitProject/hexo-source/node_modules/_resolve@1.20.0@resolve/lib/async.js:177:43)
    at onex (/home/ym/Documents/gitProject/hexo-source/node_modules/_resolve@1.20.0@resolve/lib/async.js:202:17)
    at /home/ym/Documents/gitProject/hexo-source/node_modules/_resolve@1.20.0@resolve/lib/async.js:15:69
    at FSReqCallback.oncomplete (fs.js:191:21)
    at FSReqCallback.callbackTrampoline (internal/async_hooks.js:130:17)
[00:43:37] 'default' errored after 3.75 s

@richardmyu
Copy link
Owner Author

13.husky

之前为了多端写博客,弄了一个仓库来存储非 public 部分文件,这样一来,每次写完文章,一边要推送博客,一边要提交仓库,很麻烦。

基础的推送:

# 编译
hexo g -f

# 压缩
gulp

# 推送
hexo d

不如在 package.json 中,用一行命令搞定:

"scripts": {
  // ...
  "pb": "hexo g -f && gulp && hexo d"
}

即便这样,每次,还是得分两步:推送,提交。但是同过 gitHook,可以自动完成推送。

# 安装
npm install husky -D
# husky 初始化
npx husky install
# 创建 pre-commit hook
npx husky add .husky/pre-commit "npm run pb"

package.json 修改:

"scripts": {
  // ...
  "pb": "hexo g -f && gulp && hexo d"
},
"husky" :{
  "hooks": {
    "pre-commit": "npm run pb"
  }
},

之后,按照正常 git 流程就可以了。

当然,有些时候,可能会有些修改与文章无关,即不需要推送到博客上的,可以使用 --no-verify 跳过。

git commit --no-verify -m"xxx"

@chjiyun
Copy link

chjiyun commented Apr 7, 2023

@richardmyu 我升级了node 也不行,卡在 那个包一直不动

@richardmyu richardmyu added this to Tool in Memo Jul 12, 2023
@richardmyu
Copy link
Owner Author

richardmyu commented Jan 19, 2024

14.FATAL Something's wrong.

# 2024/01/19
hexo: 7.0.0
hexo-cli: 4.3.1
os: win32 10.0.22621
node: 20.11.0
hexo-theme-next: 8.19.0

没有动 themes/next/_config.yml,而是在根目录添加了 _config.next.yml 文件,对主题的修改在此处进行。

如何推送时报错:

INFO  Start processing
FATAL Something's wrong. Maybe you can find the solution here: https://hexo.io/docs/troubleshooting.html
TypeError: Cannot read properties of undefined (reading 'enable')
    at C:\mywork\remote_project\hexo-source\themes\next\scripts\filters\comment\valine.js:11:21
    at Filter.execSync (C:\mywork\remote_project\hexo-source\node_modules\hexo\dist\extend\filter.js:72:36)
    at Hexo.execFilterSync (C:\mywork\remote_project\hexo-source\node_modules\hexo\dist\hexo\index.js:394:35)
    at module.exports (C:\mywork\remote_project\hexo-source\themes\next\scripts\events\lib\injects.js:58:8)
    at Hexo.<anonymous> (C:\mywork\remote_project\hexo-source\themes\next\scripts\events\index.js:11:27)
    at Hexo.tryCatcher (C:\mywork\remote_project\hexo-source\node_modules\bluebird\js\release\util.js:16:23)
    at Hexo.<anonymous> (C:\mywork\remote_project\hexo-source\node_modules\bluebird\js\release\method.js:15:34)
    at C:\mywork\remote_project\hexo-source\node_modules\hexo\dist\extend\filter.js:58:67
    at tryCatcher (C:\mywork\remote_project\hexo-source\node_modules\bluebird\js\release\util.js:16:23)
    at Object.gotValue (C:\mywork\remote_project\hexo-source\node_modules\bluebird\js\release\reduce.js:166:18)
    at Object.gotAccum (C:\mywork\remote_project\hexo-source\node_modules\bluebird\js\release\reduce.js:155:25)
    at Object.tryCatcher (C:\mywork\remote_project\hexo-source\node_modules\bluebird\js\release\util.js:16:23)
    at Promise._settlePromiseFromHandler (C:\mywork\remote_project\hexo-source\node_modules\bluebird\js\release\promise.js:547:31)
    at Promise._settlePromise (C:\mywork\remote_project\hexo-source\node_modules\bluebird\js\release\promise.js:604:18)
    at Promise._settlePromiseCtx (C:\mywork\remote_project\hexo-source\node_modules\bluebird\js\release\promise.js:641:10)
    at _drainQueueStep (C:\mywork\remote_project\hexo-source\node_modules\bluebird\js\release\async.js:97:12)

根据报错信息,先去查看 \themes\next\scripts\filters\comment\valine.js:11:21 文件:

if (!theme.valine.enable || !theme.valine.appid || !theme.valine.appkey) return;

根据报错信息 TypeError: Cannot read properties of undefined (reading 'enable'),可以确定是 theme.valine 不存在,这时候需要去看看主题配置文件了(themes/next/_config.yml),然后确实没有找到 valine 相关信息,去官网https://github.com/next-theme查找,终于在 【必读】更新说明及常见问题 #4找到解释了:

v8.1.0 移除 Valine
Valine 使用 Leancloud 作为后端,是一个深受静态博客用户喜爱的评论系统。然而 Valine 暴露出了一些令人担忧的问题:

NexT 团队曾多次收到关于 Valine 评论系统存在隐私数据泄露的反馈;
Valine 自 1.4 版本起不再开源,发布的打包版本中存在未告知用户的百度统计代码;
2020 年 11 月下旬出现了针对 Valine 的垃圾评论攻击;
[CVE-2021-34801](https://github.com/advisories/GHSA-p2c4-gxp4-j3xp)
考虑到这些问题已经严重影响到 NexT 用户的数据安全,我们决定将其移除,需要继续使用的用户请安装插件: https://github.com/next-theme/hexo-next-valine
(插件的配置项使用驼峰命名,与 Valine 本身一致,需要注意将 appid 和 appkey 改为 appId 和 appKey)
由于 Valine 不再开源,NexT 团队无法对其 Debug。如果在使用时出现任何问题,请在这里反馈: https://github.com/xCss/Valine/issues
从 Valine 迁移到 Disqus: https://github.com/YunYouJun/valine-to-disqus

至此,问题已解决。

1.主题配置文件(_config.next.yml)添加 valine 信息:

valine:
  enable: false

2.【不推荐】修改 \themes\next\scripts\filters\comment\valine.js 文件:

if (!theme.valine || !theme.valine.enable || !theme.valine.appid || !theme.valine.appkey) return;
// 注意,除了第 11 行,还有第 21 行

更新

v8.1 版本还有 valine.js 文件,v8.2 已经移除了。直接安装新版本(v8.2及以上)的没有这个问题,但是从 v8.2 以下版本升级的,可能会有这个问题。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Memo
Tool
Development

No branches or pull requests

2 participants