Skip to content
This repository has been archived by the owner on Jan 21, 2024. It is now read-only.

fix: halo-dev/halo#1157 #273

Merged
merged 1 commit into from
Dec 8, 2020
Merged
Show file tree
Hide file tree
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
16 changes: 14 additions & 2 deletions src/views/post/components/PostSettingDrawer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -602,9 +602,21 @@ export default {
})
},
handleSetPinyinSlug() {
if (this.selectedPost.title && !this.selectedPost.id) {
if (this.selectedPost.title && this.selectedPost.title !== '' && !this.selectedPost.id) {
if (pinyin.isSupported()) {
this.$set(this.selectedPost, 'slug', pinyin.convertToPinyin(this.selectedPost.title, '-', true))
let result = ''
const tokens = pinyin.parse(this.selectedPost.title)
let lastToken
tokens.forEach((token, i) => {
if (token.type === 2) {
const target = token.target ? token.target.toLowerCase() : ''
result += result && !/\n|\s/.test(lastToken.target) ? '-' + target : target
} else {
result += (lastToken && lastToken.type === 2 ? '-' : '') + token.target
}
lastToken = token
})
this.$set(this.selectedPost, 'slug', result)
}
}
},
Expand Down
14 changes: 13 additions & 1 deletion src/views/sheet/components/SheetSettingDrawer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,19 @@ export default {
handleSetPinyinSlug() {
if (this.selectedSheet.title && !this.selectedSheet.id) {
if (pinyin.isSupported()) {
this.$set(this.selectedSheet, 'slug', pinyin.convertToPinyin(this.selectedSheet.title, '-', true))
let result = ''
const tokens = pinyin.parse(this.selectedSheet.title)
let lastToken
tokens.forEach((token, i) => {
if (token.type === 2) {
const target = token.target ? token.target.toLowerCase() : ''
result += result && !/\n|\s/.test(lastToken.target) ? '-' + target : target
} else {
result += (lastToken && lastToken.type === 2 ? '-' : '') + token.target
}
lastToken = token
})
this.$set(this.selectedSheet, 'slug', result)
}
}
},
Expand Down