Skip to content

Commit 893e9f5

Browse files
Allow canonical_base to contain a path
1 parent eaeefd4 commit 893e9f5

File tree

5 files changed

+19
-6
lines changed

5 files changed

+19
-6
lines changed

index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
22

3-
const URL = require('url');
43
const _ = {
54
defaultsDeep: require('lodash.defaultsdeep'),
65
isEmpty : require('lodash.isempty'),
@@ -9,6 +8,7 @@ const _ = {
98
// -----------------------------------------------------------------------------
109

1110
const LIB = require('./lib');
11+
const UTIL = require('./lib/UTIL');
1212

1313
// -----------------------------------------------------------------------------
1414

@@ -361,7 +361,7 @@ PLUGIN.get_feed_url = feed =>
361361

362362
if ( feed.enable && feed.file_name )
363363
{
364-
return URL.resolve( PLUGIN.options.canonical_base, feed.file_name );
364+
return UTIL.resolve_url(PLUGIN.options.canonical_base, feed.file_name);
365365
}
366366

367367
};

lib/Head.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
22

3-
const URL = require('url');
43
const _ = { isEmpty: require('lodash.isempty') };
54

65
// -----------------------------------------------------------------------------
@@ -11,6 +10,7 @@ const { chalk: CHALK } = require('@vuepress/shared-utils');
1110

1211
const LIB = {
1312
LOG : require('./LOG'),
13+
UTIL : require('./UTIL'),
1414
};
1515

1616
// -----------------------------------------------------------------------------
@@ -59,7 +59,7 @@ class Head
5959

6060
if ( feed.head_link.enable && feed.enable && feed.file_name )
6161
{
62-
return URL.resolve( this.canonical_base, feed.file_name );
62+
return LIB.UTIL.resolve_url( this.canonical_base, feed.file_name );
6363
}
6464

6565
}

lib/Page.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
22

3-
const URL = require('url');
43
const _ = { isEmpty: require('lodash.isempty') };
54

65
// -----------------------------------------------------------------------------
@@ -96,7 +95,7 @@ class Page
9695

9796
if ( this.canonical_base && path )
9897
{
99-
return URL.resolve( this.canonical_base, path );
98+
return LIB.UTIL.resolve_url( this.canonical_base, path );
10099
}
101100

102101
}

lib/UTIL.js

+12
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,25 @@
44

55
const REMOVE_MARKDOWN = require('remove-markdown');
66
const STRIPTAGS = require('striptags');
7+
const _ = {
8+
trimEnd: require('lodash.trimend'),
9+
trimStart: require('lodash.trimstart'),
10+
};
711

812
// -----------------------------------------------------------------------------
913

1014
const UTIL = {};
1115

1216
// -----------------------------------------------------------------------------
1317

18+
19+
/**
20+
* @return {string}
21+
*/
22+
UTIL.resolve_url = (base, path) =>
23+
`${_.trimEnd( base, '/' )}/${_.trimStart( path, '/' )}`;
24+
25+
1426
/**
1527
* @return {string}
1628
*/

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
"feed": "2.0.4",
4343
"lodash.defaultsdeep": "4.6.1",
4444
"lodash.isempty": "4.4.0",
45+
"lodash.trimend": "^4.5.1",
46+
"lodash.trimstart": "^4.5.1",
4547
"remove-markdown": "0.3.0",
4648
"striptags": "3.1.1"
4749
},

0 commit comments

Comments
 (0)