feat(rocket-preset-extend-lion-docs): allow globalReplaceFunction
This commit is contained in:
parent
63f8f6fd36
commit
f46d908769
3 changed files with 45 additions and 2 deletions
5
.changeset/sweet-pillows-explode.md
Normal file
5
.changeset/sweet-pillows-explode.md
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'rocket-preset-extend-lion-docs': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
feat: allow globalReplaceFunction in rocket-preset-extend-lion-docs
|
||||||
|
|
@ -246,3 +246,40 @@ In order for such imports to work you need to define them
|
||||||
"#tabs/define": "./__element-definitions/wolf-tabs.js",
|
"#tabs/define": "./__element-definitions/wolf-tabs.js",
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Global replacements
|
||||||
|
|
||||||
|
Sometimes you need a bit more power when extending lion documentation.
|
||||||
|
For instance, you're extending repository has a different folder structure. Instead of putting your systems
|
||||||
|
documentation inside 'systems', you want to put it in 'web-systems'.
|
||||||
|
|
||||||
|
The configuration for that is (see `globalReplaceFunction`):
|
||||||
|
|
||||||
|
👉 _rocket.config.js_
|
||||||
|
|
||||||
|
```js
|
||||||
|
import { rocketLaunch } from '@rocket/launch';
|
||||||
|
import { extendLionDocs } from 'rocket-preset-extend-lion-docs';
|
||||||
|
|
||||||
|
const extendLionDocsInstance = await extendLionDocs({
|
||||||
|
classPrefix: 'Wolf',
|
||||||
|
classBareImport: 'wolf-web/',
|
||||||
|
tagPrefix: 'wolf-',
|
||||||
|
tagBareImport: 'wolf-web/',
|
||||||
|
globalReplaceFunction: node => {
|
||||||
|
if (node.type === 'link') {
|
||||||
|
// All internal links to '/systems/' (like '(../../fundamentals/systems/overlays/configuration.md)'),
|
||||||
|
// will be changed into '/web-systems/' ('(../../fundamentals/web-systems/overlays/configuration.md)').
|
||||||
|
node.url = node.url.replace(/\systems\/g, '/web-systems/');
|
||||||
|
}
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
export default {
|
||||||
|
presets: [rocketLaunch(), extendLionDocsInstance],
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
Remember: with great power comes great responsibility, so make sure your replacements do not introduce unintended
|
||||||
|
effects.
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
|
|
||||||
import { addPlugin } from 'plugins-manager';
|
import { addPlugin } from 'plugins-manager';
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import remarkExtendPkg from 'remark-extend';
|
import remarkExtendPkg from 'remark-extend';
|
||||||
|
|
@ -23,6 +22,7 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||||
* @param {string} opts.tagBareImport
|
* @param {string} opts.tagBareImport
|
||||||
* @param {string} opts.tagBareImport
|
* @param {string} opts.tagBareImport
|
||||||
* @param {string} [opts.exportsMapJsonFileName]
|
* @param {string} [opts.exportsMapJsonFileName]
|
||||||
|
* @param {function} [opts.globalReplaceFunction] a remark-extend replace function that is executed on all markdown ast nodes
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export async function extendLionDocs({
|
export async function extendLionDocs({
|
||||||
|
|
@ -34,6 +34,7 @@ export async function extendLionDocs({
|
||||||
tagPrefix,
|
tagPrefix,
|
||||||
tagBareImport,
|
tagBareImport,
|
||||||
exportsMapJsonFileName,
|
exportsMapJsonFileName,
|
||||||
|
globalReplaceFunction,
|
||||||
}) {
|
}) {
|
||||||
const changes = await generateExtendDocsConfig({
|
const changes = await generateExtendDocsConfig({
|
||||||
nodeModulesDir,
|
nodeModulesDir,
|
||||||
|
|
@ -55,7 +56,7 @@ export async function extendLionDocs({
|
||||||
setupUnifiedPlugins: [
|
setupUnifiedPlugins: [
|
||||||
addPlugin(
|
addPlugin(
|
||||||
remarkExtendPkg.remarkExtend,
|
remarkExtendPkg.remarkExtend,
|
||||||
{},
|
{ globalReplaceFunction },
|
||||||
{
|
{
|
||||||
location: markdownPkg,
|
location: markdownPkg,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue