From 5b98902937747ffd08220be82faf468fcd19e9e3 Mon Sep 17 00:00:00 2001 From: Aaron Carlino Date: Mon, 6 Jul 2020 16:04:46 +1200 Subject: [PATCH] BUGFIX: Make sure hash links aren't treated as relative (#226) --- .gitignore | 4 +++- .vscode/settings.json | 18 ------------------ src/utils/rewriteLink.ts | 13 +++++++++++++ 3 files changed, 16 insertions(+), 19 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.gitignore b/.gitignore index 84997e2..c6b4eb5 100644 --- a/.gitignore +++ b/.gitignore @@ -70,4 +70,6 @@ yarn-error.log .yarn-integrity static/_redirects -public/_redirects \ No newline at end of file +public/_redirects + +.vscode diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 85b7898..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "workbench.colorCustomizations": { - "activityBar.background": "#88d7ea", - "activityBar.activeBorder": "#de41bf", - "activityBar.foreground": "#15202b", - "activityBar.inactiveForeground": "#15202b99", - "activityBarBadge.background": "#de41bf", - "activityBarBadge.foreground": "#e7e7e7", - "titleBar.activeBackground": "#5dc9e2", - "titleBar.inactiveBackground": "#5dc9e299", - "titleBar.activeForeground": "#15202b", - "titleBar.inactiveForeground": "#15202b99", - "statusBar.background": "#5dc9e2", - "statusBarItem.hoverBackground": "#32bbda", - "statusBar.foreground": "#15202b" - }, - "peacock.color": "#5dc9e2" -} \ No newline at end of file diff --git a/src/utils/rewriteLink.ts b/src/utils/rewriteLink.ts index a95dca6..4203aaf 100644 --- a/src/utils/rewriteLink.ts +++ b/src/utils/rewriteLink.ts @@ -40,6 +40,19 @@ const rewriteLink = ( const currentNode = getCurrentNode(); const version = getCurrentVersion(); + + // hash links + if (href.startsWith('#')) { + return createElement( + Link, + { + to: path.join(currentNode?.slug, href), + className: 'gatsby-link' + }, + domToReact(children, parseOptions) + ); + } + // shorthand api links if (href.match(/^api\:/)) { const newHref = rewriteAPILink(href);