Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ruibaby authored Dec 8, 2020
1 parent 87646a2 commit 8e32dbe
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
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

0 comments on commit 8e32dbe

Please sign in to comment.