Skip to content

Commit c4d0547

Browse files
committed
#70 add slugify example in posts page in cms template
1 parent 0df7f2a commit c4d0547

File tree

1 file changed

+19
-1
lines changed
  • examples/cms/routes/app/routes/blog/routes/posts

1 file changed

+19
-1
lines changed

examples/cms/routes/app/routes/blog/routes/posts/Index.vue

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,21 @@
1414
<script>
1515
import Crud from '@/utils/crud/components/Crud.vue'
1616
17+
const slugify = (text) => {
18+
const a = 'ąàáäâćęèéëêìíïîłńòóöôśùúüûźżñçßÿœæŕśńṕẃǵǹḿǘẍźḧ·/_,:;'
19+
const b = 'aaaaaceeeeeiiiilnoooosuuuuzzncsyoarsnpwgnmuxzh------'
20+
const p = new RegExp(a.split('').join('|'), 'g')
21+
22+
return text.toString().toLowerCase()
23+
.replace(/\s+/g, '-')
24+
.replace(p, c => b.charAt(a.indexOf(c)))
25+
.replace(/&/g, '-and-')
26+
.replace(/[^\w-]+/g, '')
27+
.replace(/--+/g, '-')
28+
.replace(/^-+/, '')
29+
.replace(/-+$/, '')
30+
}
31+
1732
export default {
1833
data () {
1934
return {
@@ -62,7 +77,10 @@ export default {
6277
column: 'title',
6378
text: this.$t('fields.title'),
6479
name: 'title',
65-
multiedit: false
80+
multiedit: false,
81+
onChange: (value, fields) => {
82+
fields.find(field => field.name === 'slug').value = slugify(value)
83+
}
6684
},
6785
{
6886
type: 'input',

0 commit comments

Comments
 (0)