BUGFIX: Make sure hash links aren't treated as relative (#226)

This commit is contained in:
Aaron Carlino 2020-07-06 16:04:46 +12:00 committed by GitHub
parent c9d3bfd92e
commit 5b98902937
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 19 deletions

4
.gitignore vendored
View File

@ -70,4 +70,6 @@ yarn-error.log
.yarn-integrity
static/_redirects
public/_redirects
public/_redirects
.vscode

18
.vscode/settings.json vendored
View File

@ -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"
}

View File

@ -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);