Skip to content

Commit

Permalink
feat: replace backslashes in _processFile
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenjoezhang committed Apr 7, 2024
1 parent 67ba3e6 commit 5703a76
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
4 changes: 3 additions & 1 deletion lib/box/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: escapeBackslash(path),
params,
type
});
Expand Down
5 changes: 3 additions & 2 deletions lib/models/post_asset.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import warehouse from 'warehouse';
import { join } from 'path';
import { join, posix } from 'path';
import type Hexo from '../hexo';

export = (ctx: Hexo) => {
Expand All @@ -19,7 +19,8 @@ export = (ctx: Hexo) => {
// PostAsset.path is file path relative to `public_dir`
// no need to urlescape, #1562
// strip /\.html?$/ extensions on permalink, #2134
return join(post.path.replace(/\.html?$/, ''), this.slug);
// Replace backslashes on Windows using posix.join
return posix.join(post.path.replace(/\.html?$/, ''), this.slug);
});

PostAsset.virtual('source').get(function() {
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/tag/asset_link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<a href="${link}" title="${attrTitle}">${title}</a>`;
};
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/tag/asset_path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down

0 comments on commit 5703a76

Please sign in to comment.