Skip to content

Commit 79492ab

Browse files
committed
Fixing behaviour for when an link is root-relative.
When rendering image tags, would render the image URL from base path if the image URL is root-relative, ie starts with '/'. This is would make the behaviour of image URLs more predictable.
1 parent 1dbb547 commit 79492ab

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/core/render/compiler/image.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { getAndRemoveConfig } from '../utils';
2-
import { isAbsolutePath, getPath, getParentPath } from '../../router/util';
2+
import {
3+
isAbsolutePath,
4+
isPathRootRelative,
5+
getPath,
6+
getParentPath,
7+
} from '../../router/util';
38

49
export const imageCompiler = ({ renderer, contentBase, router }) =>
510
(renderer.image = (href, title, text) => {
@@ -35,7 +40,9 @@ export const imageCompiler = ({ renderer, contentBase, router }) =>
3540
}
3641

3742
if (!isAbsolutePath(href)) {
38-
url = getPath(contentBase, getParentPath(router.getCurrentPath()), href);
43+
url = isPathRootRelative(href)
44+
? getPath(contentBase, href)
45+
: getPath(contentBase, getParentPath(router.getCurrentPath()), href);
3946
}
4047

4148
if (attrs.length > 0) {

src/core/router/util.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ export const isAbsolutePath = cached(path => {
4444
return /(:|(\/{2}))/g.test(path);
4545
});
4646

47+
export const isPathRootRelative = cached(path => {
48+
return path[0] === '/';
49+
});
50+
4751
export const removeParams = cached(path => {
4852
return path.split(/[?#]/)[0];
4953
});

0 commit comments

Comments
 (0)