Skip to content

Commit

Permalink
fix: wrong order in spread operator, path issues
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickHeneise committed Sep 29, 2022
1 parent 32b1298 commit 04b3834
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 15 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 }
}
```
Expand Down
6 changes: 5 additions & 1 deletion src/lib/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 0 additions & 4 deletions src/lib/remark-plugins/links/index.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/serialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 0 additions & 6 deletions test/remark-plugins/links.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,3 @@ test.each(cases)(
expect(tree.children[0].url).toBe(expected)
}
)

test('fails with missing prefix', () => {
expect(() => {
relativeLinks({})
}).toThrow()
})

0 comments on commit 04b3834

Please sign in to comment.