Skip to content

Commit

Permalink
fix: properly handle relative sourcePath
Browse files Browse the repository at this point in the history
  • Loading branch information
egoist committed Dec 16, 2018
1 parent e488593 commit cc67770
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,16 @@ export const slugify = str => {

export const getFilenameByPath = (sourcePath, path) => {
sourcePath = sourcePath || './'
sourcePath = sourcePath.replace(/\/$/, '')
if (/\.md$/.test(path)) {
return sourcePath + path
sourcePath = sourcePath
// Remove leading relative path indicator, i.e. `.` and `./`
.replace(/^\.\/?/, '')
// Ensure the source path does not end with `/`
// Since out `path` has leading `/`
.replace(/(.+)\/?$/, '$1')

if (!/\.md$/.test(path)) {
path = /\/$/.test(path) ? `${path}README.md` : `${path}.md`
}
const filepath = /\/$/.test(path) ? `${path}README.md` : `${path}.md`
return sourcePath + filepath

return sourcePath + path
}

0 comments on commit cc67770

Please sign in to comment.