From 5af174bd2006d0d4464b5ab66fb5bce38b5ed3eb Mon Sep 17 00:00:00 2001 From: Bojan Djurkovic Date: Thu, 30 Mar 2017 20:26:53 -0300 Subject: [PATCH 1/3] in toURL test for anchor links and if so prepend the currentPath to the generated path. fixes #142 --- src/core/route/hash.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/core/route/hash.js b/src/core/route/hash.js index beba1f27..32c56609 100644 --- a/src/core/route/hash.js +++ b/src/core/route/hash.js @@ -66,11 +66,14 @@ export function parse (path = window.location.href) { * @param {object} qs query params */ export function toURL (path, params) { + const inline = path[0] === '#'; const route = parse(replaceSlug(path)) route.query = merge({}, route.query, params) path = route.path + stringifyQuery(route.query) path = path.replace(/\.md(\?)|\.md$/, '$1') + if (inline) path = currentPath + path; + return cleanPath('#/' + path) } From fbc75bdb956ae77bc03c0641d7f96cd743d9bd50 Mon Sep 17 00:00:00 2001 From: Bojan Djurkovic Date: Thu, 30 Mar 2017 20:37:26 -0300 Subject: [PATCH 2/3] fix code style by removing semicolons --- src/core/route/hash.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/route/hash.js b/src/core/route/hash.js index 32c56609..fd725b8b 100644 --- a/src/core/route/hash.js +++ b/src/core/route/hash.js @@ -66,14 +66,14 @@ export function parse (path = window.location.href) { * @param {object} qs query params */ export function toURL (path, params) { - const inline = path[0] === '#'; + const inline = path[0] === '#' const route = parse(replaceSlug(path)) route.query = merge({}, route.query, params) path = route.path + stringifyQuery(route.query) path = path.replace(/\.md(\?)|\.md$/, '$1') - if (inline) path = currentPath + path; + if (inline) path = currentPath + path return cleanPath('#/' + path) } From a70620387953f8f50bc0e7564610f38c029b76b2 Mon Sep 17 00:00:00 2001 From: Bojan Djurkovic Date: Fri, 31 Mar 2017 09:08:05 -0300 Subject: [PATCH 3/3] add optional current route param to toURL and use it to properly compose local anchor links --- src/core/render/compiler.js | 2 +- src/core/route/hash.js | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/core/render/compiler.js b/src/core/render/compiler.js index 0462f19a..4c7c0452 100644 --- a/src/core/render/compiler.js +++ b/src/core/render/compiler.js @@ -82,7 +82,7 @@ renderer.code = function (code, lang = '') { renderer.link = function (href, title, text) { let blank = '' if (!/:|(\/{2})/.test(href)) { - href = toURL(href) + href = toURL(href, null, currentPath) } else { blank = ' target="_blank"' } diff --git a/src/core/route/hash.js b/src/core/route/hash.js index fd725b8b..417ae96a 100644 --- a/src/core/route/hash.js +++ b/src/core/route/hash.js @@ -64,16 +64,17 @@ export function parse (path = window.location.href) { * to URL * @param {string} path * @param {object} qs query params + * @param {string} currentRoute optional current route */ -export function toURL (path, params) { - const inline = path[0] === '#' +export function toURL (path, params, currentRoute) { + const local = currentRoute && path[0] === '#' const route = parse(replaceSlug(path)) route.query = merge({}, route.query, params) path = route.path + stringifyQuery(route.query) path = path.replace(/\.md(\?)|\.md$/, '$1') - if (inline) path = currentPath + path + if (local) path = currentRoute + path return cleanPath('#/' + path) }