mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-27 22:49:56 -05:00
887caa299f
refs: #13380 - The i18n package is deprecated. It is being replaced with the tpl package.
48 lines
1.2 KiB
JavaScript
48 lines
1.2 KiB
JavaScript
const models = require('../../models');
|
|
const tpl = require('@tryghost/tpl');
|
|
const errors = require('@tryghost/errors');
|
|
|
|
const messages = {
|
|
couldNotGenerateSlug: 'Could not generate slug.'
|
|
};
|
|
const allowedTypes = {
|
|
post: models.Post,
|
|
tag: models.Tag,
|
|
user: models.User
|
|
};
|
|
|
|
module.exports = {
|
|
docName: 'slugs',
|
|
generate: {
|
|
options: [
|
|
'include',
|
|
'type'
|
|
],
|
|
data: [
|
|
'name'
|
|
],
|
|
permissions: true,
|
|
validation: {
|
|
options: {
|
|
type: {
|
|
required: true,
|
|
values: Object.keys(allowedTypes)
|
|
}
|
|
},
|
|
data: {
|
|
name: {
|
|
required: true
|
|
}
|
|
}
|
|
},
|
|
query(frame) {
|
|
return models.Base.Model.generateSlug(allowedTypes[frame.options.type], frame.data.name, {status: 'all'})
|
|
.then((slug) => {
|
|
if (!slug) {
|
|
return Promise.reject(new errors.GhostError({message: tpl(messages.couldNotGenerateSlug)}));
|
|
}
|
|
return slug;
|
|
});
|
|
}
|
|
}
|
|
};
|