mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-17 23:44:39 -05:00
Merge pull request #1408 from halfdan/1285-unidecode
Automatically replace unicode characters with ascii characters for slugs...
This commit is contained in:
commit
ab878decef
3 changed files with 16 additions and 0 deletions
|
@ -6,6 +6,7 @@ var ghostBookshelf,
|
||||||
uuid = require('node-uuid'),
|
uuid = require('node-uuid'),
|
||||||
config = require('../../../config'),
|
config = require('../../../config'),
|
||||||
Validator = require('validator').Validator,
|
Validator = require('validator').Validator,
|
||||||
|
unidecode = require('unidecode'),
|
||||||
sanitize = require('validator').sanitize;
|
sanitize = require('validator').sanitize;
|
||||||
|
|
||||||
// Initializes a new Bookshelf instance, for reference elsewhere in Ghost.
|
// Initializes a new Bookshelf instance, for reference elsewhere in Ghost.
|
||||||
|
@ -125,6 +126,8 @@ ghostBookshelf.Model = ghostBookshelf.Model.extend({
|
||||||
|
|
||||||
// Remove trailing hyphen
|
// Remove trailing hyphen
|
||||||
slug = slug.charAt(slug.length - 1) === '-' ? slug.substr(0, slug.length - 1) : slug;
|
slug = slug.charAt(slug.length - 1) === '-' ? slug.substr(0, slug.length - 1) : slug;
|
||||||
|
// Remove non ascii characters
|
||||||
|
slug = unidecode(slug);
|
||||||
// Check the filtered slug doesn't match any of the reserved keywords
|
// Check the filtered slug doesn't match any of the reserved keywords
|
||||||
slug = /^(ghost|ghost\-admin|admin|wp\-admin|wp\-login|dashboard|logout|login|signin|signup|signout|register|archive|archives|category|categories|tag|tags|page|pages|post|posts|user|users)$/g
|
slug = /^(ghost|ghost\-admin|admin|wp\-admin|wp\-login|dashboard|logout|login|signin|signup|signout|register|archive|archives|category|categories|tag|tags|page|pages|post|posts|user|users)$/g
|
||||||
.test(slug) ? slug + '-post' : slug;
|
.test(slug) ? slug + '-post' : slug;
|
||||||
|
|
|
@ -228,6 +228,18 @@ describe('Post Model', function () {
|
||||||
}).then(null, done);
|
}).then(null, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('can generate slugs without non-ascii characters', function (done) {
|
||||||
|
var newPost = {
|
||||||
|
title: 'भुते धडकी भरवणारा आहेत',
|
||||||
|
markdown: 'Test Content 1'
|
||||||
|
};
|
||||||
|
|
||||||
|
PostModel.add(newPost).then(function (createdPost) {
|
||||||
|
createdPost.get('slug').should.equal('bhute-dhddkii-bhrvnnaaraa-aahet');
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
it('detects duplicate slugs before saving', function (done) {
|
it('detects duplicate slugs before saving', function (done) {
|
||||||
var firstPost = {
|
var firstPost = {
|
||||||
title: 'First post',
|
title: 'First post',
|
||||||
|
|
|
@ -47,6 +47,7 @@
|
||||||
"showdown": "0.3.1",
|
"showdown": "0.3.1",
|
||||||
"sqlite3": "2.1.19",
|
"sqlite3": "2.1.19",
|
||||||
"underscore": "1.5.2",
|
"underscore": "1.5.2",
|
||||||
|
"unidecode": "0.1.3",
|
||||||
"validator": "1.4.0",
|
"validator": "1.4.0",
|
||||||
"when": "2.5.1"
|
"when": "2.5.1"
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Reference in a new issue