From 12dceeb51b1152e91e2ee425a4ec9e86f747e3b5 Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Sun, 7 Apr 2024 09:15:17 +0800 Subject: [PATCH] feat: replace backslashes in _processFile --- lib/box/index.ts | 4 +++- lib/plugins/tag/asset_link.ts | 2 +- lib/plugins/tag/asset_path.ts | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/box/index.ts b/lib/box/index.ts index e55079c8de..a4d9eeff2f 100644 --- a/lib/box/index.ts +++ b/lib/box/index.ts @@ -160,8 +160,10 @@ class Box extends EventEmitter { if (!params) return count; const file = new File({ + // source is used for filesystem path, keep backslashes on Windows source: join(base, path), - path, + // path is used for URL path, replace backslashes on Windows + path: path.replace(/\\/g, '/'), params, type }); diff --git a/lib/plugins/tag/asset_link.ts b/lib/plugins/tag/asset_link.ts index 720c40cc46..ae4014744c 100644 --- a/lib/plugins/tag/asset_link.ts +++ b/lib/plugins/tag/asset_link.ts @@ -28,7 +28,7 @@ export = (ctx: Hexo) => { const attrTitle = escapeHTML(title); if (escape === 'true') title = attrTitle; - const link = url_for.call(ctx, asset.path.replace(/\\/g, '/')); + const link = url_for.call(ctx, asset.path); return `${title}`; }; diff --git a/lib/plugins/tag/asset_path.ts b/lib/plugins/tag/asset_path.ts index 09209a1daa..e8c7dbad5d 100644 --- a/lib/plugins/tag/asset_path.ts +++ b/lib/plugins/tag/asset_path.ts @@ -17,7 +17,7 @@ export = (ctx: Hexo) => { const asset = PostAsset.findOne({post: this._id, slug}); if (!asset) return; - const path = url_for.call(ctx, asset.path.replace(/\\/g, '/')); + const path = url_for.call(ctx, asset.path); return path; };