Slug management : awtis & mizik to slug
This commit is contained in:
@@ -1,8 +1,25 @@
|
|||||||
'use strict';
|
'use strict'
|
||||||
|
|
||||||
/**
|
const slugify = require('slugify')
|
||||||
* Read the documentation (https://strapi.io/documentation/v3.x/concepts/models.html#lifecycle-hooks)
|
|
||||||
* to customize this model
|
|
||||||
*/
|
|
||||||
|
|
||||||
module.exports = {};
|
const jwennAwtisEpiId = async data => {
|
||||||
|
const awtis = await strapi.query('awtis').find({_id: data})
|
||||||
|
return awtis.map(a => a.alias).join('-')
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
lifecycles: {
|
||||||
|
beforeCreate: async data => {
|
||||||
|
if (data.titre) {
|
||||||
|
const awtis = await jwennAwtisEpiId(data.awtis)
|
||||||
|
data.slug = slugify(`${awtis}-${data.titre}`, {lower: true, remove: /[*+~.()'"!:@]/g})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
beforeUpdate: async (params, data) => {
|
||||||
|
if (data.titre) {
|
||||||
|
const awtis = await jwennAwtisEpiId(data.awtis)
|
||||||
|
data.slug = slugify(`${awtis}-${data.titre}`, {lower: true, remove: /[*+~.()'"!:@]/g})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user