From b9751f6d6fc4a54b6c7eece973653416c6d03a4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E8=BF=9B=E7=A6=84?= Date: Mon, 14 Mar 2022 16:26:12 +0800 Subject: [PATCH] filter.js --- scripts/filter.js | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 scripts/filter.js diff --git a/scripts/filter.js b/scripts/filter.js new file mode 100644 index 0000000..88f4cc3 --- /dev/null +++ b/scripts/filter.js @@ -0,0 +1,11 @@ +// 替换markdown中图片路径的正则 +const mdImageRegex = /\]\s*\((?=(?!http).*?\))/gi +// 替换所有HTML标签的正则 +hexo.extend.filter.register('before_post_render', function(article){ + // article.raw 是原始的文件内容 + // article.content 是处理过代码块语法高亮的内容 + if(hexo.config.picture_cdn) { + article.content = article.content.replace(mdImageRegex, `](${hexo.config.picture_cdn}`) + } + return article +}) \ No newline at end of file