Ryan Wang 2020-12-08 09:59:49 +08:00 committed by GitHub
parent 87646a214e
commit 8e32dbe397
2 changed files with 27 additions and 3 deletions

View File

@ -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)
}
}
},

View File

@ -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)
}
}
},