fix(rocket-preset-extend-lion-docs): windows compatibility
This commit is contained in:
parent
b90ed14234
commit
f303ed6866
2 changed files with 21 additions and 6 deletions
5
.changeset/polite-hairs-shave.md
Normal file
5
.changeset/polite-hairs-shave.md
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'rocket-preset-extend-lion-docs': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
windows compatibility
|
||||||
|
|
@ -12,15 +12,26 @@ import visit from 'unist-util-visit';
|
||||||
|
|
||||||
/** @typedef {Node & UrlProperty} UrlNode */
|
/** @typedef {Node & UrlProperty} UrlNode */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} pathStr C:\Example\path/like/this
|
||||||
|
* @returns {string} /Example/path/like/this
|
||||||
|
*/
|
||||||
|
function toPosixPath(pathStr) {
|
||||||
|
if (process.platform === 'win32') {
|
||||||
|
return pathStr.replace(/^.:/, '').replace(/\\/g, '/');
|
||||||
|
}
|
||||||
|
return pathStr;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {object} opts
|
* @param {object} opts
|
||||||
* @param {string} opts.gitHubUrl
|
* @param {string} opts.gitHubUrl
|
||||||
* @param {object} opts.page
|
* @param {{inputPath:string}} opts.page
|
||||||
* @param {string} opts.page.inputPath
|
|
||||||
* @param {string} opts.rootDir
|
* @param {string} opts.rootDir
|
||||||
* @returns
|
|
||||||
*/
|
*/
|
||||||
export function remarkUrlToLocal({ gitHubUrl, page, rootDir }) {
|
export function remarkUrlToLocal({ gitHubUrl, page, rootDir }) {
|
||||||
|
const inputPath = toPosixPath(page.inputPath);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {UrlNode} node
|
* @param {UrlNode} node
|
||||||
*/
|
*/
|
||||||
|
|
@ -34,10 +45,9 @@ export function remarkUrlToLocal({ gitHubUrl, page, rootDir }) {
|
||||||
urlParts.shift();
|
urlParts.shift();
|
||||||
urlParts.shift();
|
urlParts.shift();
|
||||||
const fullUrlPath = path.join(rootDir, urlParts.join('/'));
|
const fullUrlPath = path.join(rootDir, urlParts.join('/'));
|
||||||
const fullInputPath =
|
const fullInputPath = inputPath[0] === '/' ? inputPath : path.join(rootDir, inputPath);
|
||||||
page.inputPath[0] === '/' ? page.inputPath : path.join(rootDir, page.inputPath);
|
|
||||||
const newPath = path.relative(path.dirname(fullInputPath), fullUrlPath);
|
const newPath = path.relative(path.dirname(fullInputPath), fullUrlPath);
|
||||||
node.url = newPath;
|
node.url = toPosixPath(newPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue