@@ -5,6 +5,7 @@ const { escape } = require('marked/src/helpers');
5
5
const { encodeURL, slugize, stripHTML, url_for, isExternalLink } = require ( 'hexo-util' ) ;
6
6
const MarkedRenderer = marked . Renderer ;
7
7
const MarkedTokenizer = marked . Tokenizer ;
8
+ const { basename, dirname, extname, join } = require ( 'path' ) . posix ;
8
9
9
10
const anchorId = ( str , transformOption ) => {
10
11
return slugize ( str . trim ( ) , { transform : transformOption } ) ;
@@ -103,7 +104,7 @@ class Renderer extends MarkedRenderer {
103
104
if ( ! href . startsWith ( '/' ) && ! href . startsWith ( '\\' ) && postPath ) {
104
105
const PostAsset = hexo . model ( 'PostAsset' ) ;
105
106
// findById requires forward slash
106
- const asset = PostAsset . findById ( postPath + href . replace ( / \\ / g, '/' ) ) ;
107
+ const asset = PostAsset . findById ( join ( postPath , href . replace ( / \\ / g, '/' ) ) ) ;
107
108
// asset.path is backward slash in Windows
108
109
if ( asset ) href = asset . path . replace ( / \\ / g, '/' ) ;
109
110
}
@@ -234,7 +235,10 @@ module.exports = function(data, options) {
234
235
// Windows compatibility, Post.findOne() requires forward slash
235
236
const source = path . substring ( this . source_dir . length ) . replace ( / \\ / g, '/' ) ;
236
237
const post = Post . findOne ( { source } ) ;
237
- postPath = post ? source_dir + '/_posts/' + post . slug + '/' : '' ;
238
+ if ( post ) {
239
+ const { source : postSource } = post ;
240
+ postPath = join ( source_dir , dirname ( postSource ) , basename ( postSource , extname ( postSource ) ) ) ;
241
+ }
238
242
}
239
243
240
244
return marked ( text , Object . assign ( {
0 commit comments