diff --git a/README.md b/README.md index 0b228be..3f9a129 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,7 @@ where documentation content is stored at ### Additional options ```jsx -skipPathPrefix: false + skipPathPrefix: false, ``` Can be used if the docs are not located in the root of the repository. @@ -152,7 +152,7 @@ export async function getStaticPaths() { } export async function getStaticProps(ctx) { - const props = await pageProps(ctx, docOptions) + const props = await pageProps(ctx, docsOptions) return { props } } ``` diff --git a/src/lib/docs.js b/src/lib/docs.js index f6b3da1..4acc329 100644 --- a/src/lib/docs.js +++ b/src/lib/docs.js @@ -48,7 +48,11 @@ export function findRouteByPath(path, routes, options) { if (childPath) { // check if the routes in the manifest start with the docsFolder if (!childPath.path.startsWith(options.docsFolder)) { - childPath.path = `/${options.docsFolder}${childPath.path}` + if (options.skipPathPrefix) { + childPath.path = `${childPath.path}` + } else { + childPath.path = `/${options.docsFolder}${childPath.path}` + } } return childPath } diff --git a/src/lib/files.js b/src/lib/files.js index 3621895..4105bb7 100644 --- a/src/lib/files.js +++ b/src/lib/files.js @@ -49,7 +49,7 @@ async function getRawFileFromFS(path, options) { export function getRawFile(path, options) { if (options.debug) { - console.log(path) + console.log('path:', path) } const { org, repo, tag } = options if (!org || !repo || !tag) { diff --git a/src/lib/remark-plugins/links/index.js b/src/lib/remark-plugins/links/index.js index 346a591..06767e4 100644 --- a/src/lib/remark-plugins/links/index.js +++ b/src/lib/remark-plugins/links/index.js @@ -1,10 +1,6 @@ import { visit } from 'unist-util-visit' export default function relativeLinks(options) { - if (!options || !options.prefix) { - throw Error('Missing required "prefix" option') - } - let pathParts = [] let extensions = ['.mdx', '.md'] const slug = options.slug diff --git a/src/serialize.js b/src/serialize.js index b18509f..19caa1d 100644 --- a/src/serialize.js +++ b/src/serialize.js @@ -173,7 +173,7 @@ export async function pageProps(context, args) { } export async function staticPaths(args) { - const options = { ...args, ...defaults } + const options = { ...defaults, ...args } const { docsFolder, skipPathPrefix } = options const manifest = await fetchDocsManifest(docsFolder, options) diff --git a/test/remark-plugins/links.test.js b/test/remark-plugins/links.test.js index fb04f62..0f28225 100644 --- a/test/remark-plugins/links.test.js +++ b/test/remark-plugins/links.test.js @@ -167,9 +167,3 @@ test.each(cases)( expect(tree.children[0].url).toBe(expected) } ) - -test('fails with missing prefix', () => { - expect(() => { - relativeLinks({}) - }).toThrow() -})