Skip to content

Commit 0bbf896

Browse files
committed
sync implementation of relativize for Antora core
1 parent 62e3c33 commit 0bbf896

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,20 @@ function copyImages (src, dest) {
114114
.pipe(map((file, enc, next) => next()))
115115
}
116116

117-
function relativize (to, { data }) {
117+
function relativize (to, { data: { root } }) {
118118
if (!to) return '#'
119119
if (to.charAt() !== '/') return to
120-
const from = data.root.page.url
120+
const from = root.page.url
121+
if (!from) return (root.site.path || '') + to
122+
let hash = ''
121123
const hashIdx = to.indexOf('#')
122-
if (~hashIdx && to.substr(0, hashIdx) === from) return to.substr(hashIdx)
123-
return to.substr(1)
124+
if (~hashIdx) {
125+
hash = to.substr(hashIdx)
126+
to = to.substr(0, hashIdx)
127+
}
128+
return to === from
129+
? hash || (to.charAt(to.length - 1) === '/' ? './' : path.basename(to))
130+
: (path.relative(path.dirname(from + '.'), to) || '.') + (to.charAt(to.length - 1) === '/' ? '/' + hash : hash)
124131
}
125132

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

0 commit comments

Comments
 (0)