From 13dcc5d4424d2f5526940aebe07ec21886d45d65 Mon Sep 17 00:00:00 2001 From: Guy Sartorelli <36352093+GuySartorelli@users.noreply.github.com> Date: Mon, 19 Feb 2024 09:26:23 +1300 Subject: [PATCH] FEAT Add linkfield docs (#286) --- gatsby-node.js | 2 +- sources-docs.js | 9 +++++++++ src/utils/rewriteLink.ts | 28 +++++++++++++++++++++++++++- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/gatsby-node.js b/gatsby-node.js index cfdb889..7d6de76 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -48,7 +48,7 @@ exports.onCreateNode = async ({ node, getNode, getNodesByType, actions, createNo } return; } - const basePath = category === 'user' ? `docs/en/userguide` : `en`; + const basePath = category === 'user' ? 'docs/en/userguide' : (thirdparty ? 'docs/en' : 'en'); const filePath = createFilePath({ node, getNode, diff --git a/sources-docs.js b/sources-docs.js index 8a9fc68..9b5d305 100644 --- a/sources-docs.js +++ b/sources-docs.js @@ -8,6 +8,15 @@ module.exports = [ patterns: 'en/**' } }, + { + resolve: 'gatsby-source-git', + options: { + name: 'docs--5--optional_features/linkfield', + remote: 'https://github.com/silverstripe/silverstripe-linkfield.git', + branch: '4.0', + patterns: 'docs/en/**' + } + }, { resolve: 'gatsby-source-git', options: { diff --git a/src/utils/rewriteLink.ts b/src/utils/rewriteLink.ts index d1fe88c..10090e5 100644 --- a/src/utils/rewriteLink.ts +++ b/src/utils/rewriteLink.ts @@ -96,7 +96,33 @@ const rewriteLink = ( ) } - // absolute links + // absolute links to docs (unversioned) + if (href.match(/^https?:\/\/docs.silverstripe.org\/en\/[a-zA-Z]/)) { + return createElement( + Link, + { + to: path.join('/', 'en', version, href.replace(/^https?:\/\/docs.silverstripe.org\/en/, '')), + className: 'gatsby-link' + }, + domToReact(children, parseOptions) + ); + } + + // absolute links to docs (versioned) + const hrefMatch = href.match(/^https?:\/\/docs.silverstripe.org\/en\/([0-9]+)/); + if (hrefMatch) { + const hrefVersion = hrefMatch[1]; + return createElement( + Link, + { + to: path.join('/', 'en', hrefVersion, href.replace(/^https?:\/\/docs.silverstripe.org\/en\/([0-9]+)/, '')), + className: 'gatsby-link' + }, + domToReact(children, parseOptions) + ); + } + + // absolute links to anywhere else if (href.match(/^https?/)) { return createElement( 'a',