From b412671e9216ae126b9267488f0b143ad6fed837 Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Fri, 29 Oct 2021 21:47:22 +0800 Subject: [PATCH] feat: support resetting post slug #319 (#368) --- .../post/components/PostSettingDrawer.vue | 22 +++++++++++++++---- .../sheet/components/SheetSettingDrawer.vue | 22 +++++++++++++++---- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/views/post/components/PostSettingDrawer.vue b/src/views/post/components/PostSettingDrawer.vue index 469295a3..26b164bc 100644 --- a/src/views/post/components/PostSettingDrawer.vue +++ b/src/views/post/components/PostSettingDrawer.vue @@ -18,7 +18,19 @@ - + + + @@ -387,7 +399,9 @@ export default { this.handleListCategories() this.handleListPresetMetasField() this.handleListCustomTpls() - this.handleSetPinyinSlug() + if (!this.selectedPost.slug && !this.selectedPost.id) { + this.handleSetPinyinSlug() + } } }, handleListCategories() { @@ -534,10 +548,10 @@ export default { }) }, handleSetPinyinSlug() { - if (this.selectedPost.title && this.selectedPost.title !== '' && !this.selectedPost.id) { + if (this.selectedPost.title) { if (pinyin.isSupported()) { let result = '' - const tokens = pinyin.parse(this.selectedPost.title) + const tokens = pinyin.parse(this.selectedPost.title.replace(/\s+/g, '').toLowerCase()) let lastToken tokens.forEach(token => { if (token.type === 2) { diff --git a/src/views/sheet/components/SheetSettingDrawer.vue b/src/views/sheet/components/SheetSettingDrawer.vue index 920583dc..ea8dc3fc 100644 --- a/src/views/sheet/components/SheetSettingDrawer.vue +++ b/src/views/sheet/components/SheetSettingDrawer.vue @@ -18,7 +18,19 @@ - + + + { if (token.type === 2) {