From 60880b3f77f56a7c39a063b3fccbbb9b5a641839 Mon Sep 17 00:00:00 2001 From: Billyyyyy3320 Date: Sun, 18 Aug 2019 00:11:26 +0800 Subject: [PATCH] feat($shared-utils): resolve regularPath when getting permalink --- packages/@vuepress/shared-utils/src/getPermalink.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/@vuepress/shared-utils/src/getPermalink.ts b/packages/@vuepress/shared-utils/src/getPermalink.ts index 761de1de9b..f8daa86c57 100644 --- a/packages/@vuepress/shared-utils/src/getPermalink.ts +++ b/packages/@vuepress/shared-utils/src/getPermalink.ts @@ -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 @@ -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 + @@ -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)) }