Skip to content

Commit 8320484

Browse files
committed
Fix GitbookIO#647: Fix links normalization (content and hash)
1 parent 0e243e6 commit 8320484

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

lib/utils/page.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -190,17 +190,17 @@ function normalizeHtml(src, options) {
190190
if (links.isAnchor(href)) {
191191
// Keep it as it is
192192
} else if (links.isRelative(href)) {
193-
var parts = url.parse(path.join(options.base, href));
194-
var absolutePath = parts.pathname;
195-
var anchor = parts.hash;
193+
var parts = url.parse(href);
194+
var absolutePath = path.join(options.base, parts.pathname);
195+
var anchor = parts.hash || "";
196196

197197
// If is in navigation relative: transform as content
198198
if (options.navigation[absolutePath]) {
199-
href = options.book.contentLink(href);
199+
absolutePath = options.book.contentLink(absolutePath);
200200
}
201201

202202
// Transform as absolute
203-
href = links.toAbsolute(href, options.base, options.output)+anchor;
203+
href = links.toAbsolute("/"+absolutePath, options.base, options.output)+anchor;
204204
} else {
205205
// External links
206206
$(this).attr("target", "_blank");

test/json.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('JSON generator', function () {
2121
assert(fs.existsSync(path.join(output, "sub/test1.json")));
2222

2323
var test1 = JSON.parse(fs.readFileSync(path.join(output, "sub/test1.json")));
24-
assert(test1.sections[0].content.indexOf("intro.html") > 0);
24+
assert(test1.sections[0].content.indexOf("index.html") > 0);
2525
}, done);
2626
});
2727

0 commit comments

Comments
 (0)