BUGFIX: Ensure .md links with hashes are rewritten properly (#228)
* Upgrade gatsby * BUGFIX: ensure .md links with hashes are rewritten properly
This commit is contained in:
parent
33458d485f
commit
c9d3bfd92e
|
@ -20,6 +20,7 @@ const relativeLink = (currentNode: SilverstripeDocument, href: string): string =
|
||||||
return slug;
|
return slug;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensure links use the Gatsby <Link /> component. Client-side routing FTW
|
* Ensure links use the Gatsby <Link /> component. Client-side routing FTW
|
||||||
*
|
*
|
||||||
|
@ -39,7 +40,6 @@ const rewriteLink = (
|
||||||
|
|
||||||
const currentNode = getCurrentNode();
|
const currentNode = getCurrentNode();
|
||||||
const version = getCurrentVersion();
|
const version = getCurrentVersion();
|
||||||
|
|
||||||
// shorthand api links
|
// shorthand api links
|
||||||
if (href.match(/^api\:/)) {
|
if (href.match(/^api\:/)) {
|
||||||
const newHref = rewriteAPILink(href);
|
const newHref = rewriteAPILink(href);
|
||||||
|
@ -90,7 +90,6 @@ const rewriteLink = (
|
||||||
|
|
||||||
// Relative to page
|
// Relative to page
|
||||||
if (currentNode && currentNode.parentSlug) {
|
if (currentNode && currentNode.parentSlug) {
|
||||||
|
|
||||||
// Relative links to markdown files should be resolved to their pretty urls.
|
// Relative links to markdown files should be resolved to their pretty urls.
|
||||||
if (href.endsWith('.md')) {
|
if (href.endsWith('.md')) {
|
||||||
return createElement(
|
return createElement(
|
||||||
|
@ -102,6 +101,22 @@ const rewriteLink = (
|
||||||
domToReact(children, parseOptions)
|
domToReact(children, parseOptions)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
const hashMatches = href.match(/(\.md#([A-Za-z0-9_-]+))$/);
|
||||||
|
if (hashMatches) {
|
||||||
|
const newHashLink = href.replace(
|
||||||
|
new RegExp(`${hashMatches[1]}$`),
|
||||||
|
`#${hashMatches[2]}`
|
||||||
|
);
|
||||||
|
|
||||||
|
return createElement(
|
||||||
|
Link,
|
||||||
|
{
|
||||||
|
to: relativeLink(currentNode, newHashLink).replace(/\/$/, ''),
|
||||||
|
className: 'gatsby-link',
|
||||||
|
},
|
||||||
|
domToReact(children, parseOptions)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return createElement(
|
return createElement(
|
||||||
Link,
|
Link,
|
||||||
|
|
Loading…
Reference in New Issue