File tree Expand file tree Collapse file tree 6 files changed +10
-16
lines changed
Expand file tree Collapse file tree 6 files changed +10
-16
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ export = (ctx: Hexo) => {
1818 for ( let i = 0 ; i < len ; i ++ ) {
1919 const asset = PostAsset . findOne ( { post : this . _id , slug : args [ i ] } ) ;
2020 if ( asset ) {
21+ // img tag will call url_for so no need to call it here
2122 args [ i ] = encodeURL ( new URL ( asset . path , ctx . config . url ) . pathname ) ;
2223 return img ( ctx ) ( args ) ;
2324 }
Original file line number Diff line number Diff line change 1- import { encodeURL , escapeHTML } from 'hexo-util' ;
1+ import { url_for , escapeHTML } from 'hexo-util' ;
22import type Hexo from '../../hexo' ;
33
44/**
@@ -28,7 +28,7 @@ export = (ctx: Hexo) => {
2828 const attrTitle = escapeHTML ( title ) ;
2929 if ( escape === 'true' ) title = attrTitle ;
3030
31- const link = encodeURL ( new URL ( asset . path , ctx . config . url ) . pathname ) ;
31+ const link = url_for . call ( ctx , asset . path . replace ( / \\ / g , '/' ) ) ;
3232
3333 return `<a href="${ link } " title="${ attrTitle } ">${ title } </a>` ;
3434 } ;
Original file line number Diff line number Diff line change 1- import { encodeURL } from 'hexo-util' ;
1+ import { url_for } from 'hexo-util' ;
22import type Hexo from '../../hexo' ;
33
44/**
@@ -17,7 +17,7 @@ export = (ctx: Hexo) => {
1717 const asset = PostAsset . findOne ( { post : this . _id , slug} ) ;
1818 if ( ! asset ) return ;
1919
20- const path = encodeURL ( new URL ( asset . path , ctx . config . url ) . pathname ) ;
20+ const path = url_for . call ( ctx , asset . path . replace ( / \\ / g , '/' ) ) ;
2121
2222 return path ;
2323 } ;
Original file line number Diff line number Diff line change 1- import { encodeURL , escapeHTML } from 'hexo-util' ;
1+ import { url_for , encodeURL , escapeHTML } from 'hexo-util' ;
22import { postFindOneFactory } from './' ;
33import type Hexo from '../../hexo' ;
44
@@ -41,14 +41,7 @@ export = (ctx: Hexo) => {
4141 const attrTitle = escapeHTML ( post . title || post . slug ) ;
4242 if ( escape === 'true' ) title = escapeHTML ( title ) ;
4343
44- // guarantee the base url ends with a slash. (case of using a subdirectory in the url of the site)
45- let baseUrl = ctx . config . url ;
46- if ( ! baseUrl . endsWith ( '/' ) ) {
47- baseUrl += '/' ;
48- }
49-
50- const url = new URL ( post . path , baseUrl ) . pathname + ( hash ? `#${ hash } ` : '' ) ;
51- const link = encodeURL ( url ) ;
44+ const link = url_for . call ( ctx , post . path + ( hash ? `#${ hash } ` : '' ) ) ;
5245
5346 return `<a href="${ link } " title="${ attrTitle } ">${ title } </a>` ;
5447 } ;
Original file line number Diff line number Diff line change 1- import { encodeURL } from 'hexo-util' ;
1+ import { url_for } from 'hexo-util' ;
22import { postFindOneFactory } from './' ;
33import type Hexo from '../../hexo' ;
44
@@ -17,7 +17,7 @@ export = (ctx: Hexo) => {
1717 const post = factory ( { slug } ) || factory ( { title : slug } ) ;
1818 if ( ! post ) return ;
1919
20- const link = encodeURL ( new URL ( post . path , ctx . config . url ) . pathname ) ;
20+ const link = url_for . call ( ctx , post . path ) ;
2121
2222 return link ;
2323 } ;
Original file line number Diff line number Diff line change @@ -81,7 +81,7 @@ describe('post_link', () => {
8181 } ) ;
8282
8383 it ( 'should keep subdir' , ( ) => {
84- hexo . config . url = 'http://example.com/ subdir' ;
84+ hexo . config . root = '/ subdir/ ' ;
8585 postLink ( [ 'foo' ] ) . should . eql ( '<a href="/subdir/foo/" title="Hello world">Hello world</a>' ) ;
8686 } ) ;
8787} ) ;
You can’t perform that action at this time.
0 commit comments