Skip to content

Commit c12db11

Browse files
committed
fix relativize function used by UI preview [skip ci]
1 parent 91d6945 commit c12db11

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

gulp.d/tasks/build-preview-pages.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,13 @@ function copyImages (src, dest) {
118118
.pipe(map((file, enc, next) => next()))
119119
}
120120

121-
function relativize (url) {
122-
return url ? (url.charAt() === '#' ? url : url.slice(1)) : '#'
121+
function relativize (to, { data }) {
122+
if (!to) return '#'
123+
if (to.charAt() !== '/') return to
124+
const from = data.root.page.url
125+
const hashIdx = to.indexOf('#')
126+
if (~hashIdx && to.substr(0, hashIdx) === from) return to.substr(hashIdx)
127+
return to.substr(1)
123128
}
124129

125130
function resolvePage (spec, context = {}) {

0 commit comments

Comments
 (0)