FEAT Add linkfield docs (#286)

This commit is contained in:
Guy Sartorelli 2024-02-19 09:26:23 +13:00 committed by GitHub
parent 8ce02bcf8e
commit 13dcc5d442
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 37 additions and 2 deletions

View File

@ -48,7 +48,7 @@ exports.onCreateNode = async ({ node, getNode, getNodesByType, actions, createNo
} }
return; return;
} }
const basePath = category === 'user' ? `docs/en/userguide` : `en`; const basePath = category === 'user' ? 'docs/en/userguide' : (thirdparty ? 'docs/en' : 'en');
const filePath = createFilePath({ const filePath = createFilePath({
node, node,
getNode, getNode,

View File

@ -8,6 +8,15 @@ module.exports = [
patterns: 'en/**' 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', resolve: 'gatsby-source-git',
options: { options: {

View File

@ -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?/)) { if (href.match(/^https?/)) {
return createElement( return createElement(
'a', 'a',