Hexo问题

hexo在线查看pdf

场景 #

由于在看《mysql是如何运行的》,做md文件笔记时,发现好多都是按pdf一字不漏打出来。所以想着能不能直接本地编辑pdf,然后博客上支持在线查看

事后觉得这个方式有待斟酌,电脑上/平板上查看没啥问题,手机上查看字有点小,但也还能接受。==>待斟酌
不过下面的方案是可行的。

准备 #

需要到官网下载 pdf.js

https://github.com/mozilla/pdf.js/releases ,这里选择 v3.4.120中的 pdfjs-3.4.120-dist.zip ,最新版本好像有问题

操作 #

pdfjs处理 #

在source/下创建myjs/pdfjs文件夹,并解压到这个文件夹下
ly-20241212141830564

修改pdfjs/web/viewer.js

if (fileOrigin !== viewerOrigin) {//1563行左右
	throw new Error("file origin does not match viewer's");
}
//注释掉,为了处理跨域问题,注释掉后允许在线访问其他网站的pdf
// if (fileOrigin !== viewerOrigin) {
//	throw new Error("file origin does not match viewer's");
//}

hexo配置修改 #

# 找到# Directory下的skip_render项,添加忽略渲染的文件夹
skip_render:  ['myjs/pdfjs/**/*']

清理hexo中public及其他缓存文件 #

 hexo clean & hexo g

文件预览测试 #

本地文件 #

我们在hexo的source文件夹下,放置这样一个文件: source/pdf/my.pdf
ly-20241212141830812

...