Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat($shared-utils): remove leading slash of regularPath when getting permalink #1786

Merged
merged 1 commit into from
Sep 22, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions packages/@vuepress/shared-utils/src/getPermalink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ interface PermalinkOption {
localePath: string;
}

function removeLeadingSlash (path: string) {
return path.replace(/^\//, '')
}
// e.g.
// filename: docs/_posts/evan you.md
// content: # yyx 990803
Expand Down Expand Up @@ -39,8 +42,7 @@ export = function getPermalink ({
const month = iMonth < 10 ? `0${iMonth}` : iMonth
const day = iDay < 10 ? `0${iDay}` : iDay

// Remove leading slash
pattern = pattern.replace(/^\//, '')
pattern = removeLeadingSlash(pattern)

const link =
localePath +
Expand All @@ -53,7 +55,7 @@ export = function getPermalink ({
.replace(/:minutes/, String(minutes))
.replace(/:seconds/, String(seconds))
.replace(/:slug/, slug)
.replace(/:regular/, regularPath)
.replace(/:regular/, removeLeadingSlash(regularPath))

return ensureLeadingSlash(ensureEndingSlash(link))
}