Skip to content

Commit 5e81886

Browse files
committed
Refactor slugify calls to remove stripAccents option for consistency
1 parent 3f48b5b commit 5e81886

File tree

6 files changed

+14
-20
lines changed

6 files changed

+14
-20
lines changed

modules/@apostrophecms/attachment/index.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -421,10 +421,7 @@ module.exports = {
421421
_id: options.attachmentId ?? self.apos.util.generateId(),
422422
group: group.name,
423423
createdAt: new Date(),
424-
name: self.apos.util.slugify(
425-
path.basename(fileName, path.extname(fileName)),
426-
{ stripAccents: self.apos.i18n.shouldStripAccents(req) }
427-
),
424+
name: self.apos.util.slugify(path.basename(fileName, path.extname(fileName))),
428425
title: self.apos.util.sortify(
429426
path.basename(fileName, path.extname(fileName))
430427
),

modules/@apostrophecms/doc/index.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,7 @@ module.exports = {
218218
'@apostrophecms/doc-type:beforeSave': {
219219
ensureSlugSortifyAndUpdatedAt(req, doc, options) {
220220
const manager = self.getManager(doc.type);
221-
manager.ensureSlug(
222-
doc,
223-
{
224-
stripAccents: self.apos.i18n.shouldStripAccents(req)
225-
}
226-
);
221+
manager.ensureSlug(doc);
227222
_.each(manager.schema, function (field) {
228223
if (field.sortify) {
229224
doc[field.name + 'Sortified'] = self.apos.util.sortify(

modules/@apostrophecms/page-type/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,14 +468,14 @@ module.exports = {
468468
},
469469
// If the page does not yet have a slug, add one based on the
470470
// title; throw an error if there is no title
471-
ensureSlug(page, { stripAccents } = {}) {
471+
ensureSlug(page) {
472472
if (!page.slug || (!page.slug.match(/^\//))) {
473473
if (page.title) {
474474
// Parent-based slug would be better, but this is not an
475475
// async function and callers will typically have done
476476
// that already, so skip the overhead. This is just a fallback
477477
// for naive use of the APIs
478-
page.slug = '/' + self.apos.util.slugify(page.title, { stripAccents });
478+
page.slug = '/' + self.apos.util.slugify(page.title);
479479
} else {
480480
throw self.apos.error('invalid', 'Page has neither a slug beginning with / or a title, giving up');
481481
}

modules/@apostrophecms/piece-type/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,10 +1146,10 @@ module.exports = {
11461146
},
11471147
// If the piece does not yet have a slug, add one based on the
11481148
// title; throw an error if there is no title
1149-
ensureSlug(piece, { stripAccents } = {}) {
1149+
ensureSlug(piece) {
11501150
if (!piece.slug || piece.slug === 'none') {
11511151
if (piece.title) {
1152-
piece.slug = self.apos.util.slugify(piece.title, { stripAccents });
1152+
piece.slug = self.apos.util.slugify(piece.title);
11531153
} else if (piece.slug !== 'none') {
11541154
throw self.apos.error(
11551155
'invalid',

modules/@apostrophecms/schema/lib/addFieldTypes.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ module.exports = (self) => {
186186
// (no slashes at all)
187187
convert (req, field, data, destination) {
188188
const options = self.getSlugFieldOptions(field, data);
189-
options.stripAccents = self.apos.i18n.shouldStripAccents(req);
190189

191190
destination[field.name] = self.apos.util.slugify(
192191
self.apos.launder.string(data[field.name]),

modules/@apostrophecms/util/index.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -291,12 +291,15 @@ module.exports = {
291291
// ONE punctuation character normally forbidden in slugs may
292292
// optionally be permitted by specifying it via options.allow.
293293
// The separator may be changed via options.separator.
294-
// By default, accents are preserved. To strip accents,
295-
// set options.stripAccents to true.
294+
// By default, the i18n.options.stripUrlAccents option is honored;
295+
// having stripAccents passed as an option takes precedence.
296296
slugify(s, options) {
297297
const { stripAccents, ...opts } = options || {};
298298
const slug = require('sluggo')(s, opts);
299-
if (stripAccents) {
299+
const shouldStripAccents = (typeof stripAccents !== 'undefined')
300+
? stripAccents
301+
: self.apos.i18n.options.stripUrlAccents;
302+
if (shouldStripAccents) {
300303
return _.deburr(slug);
301304
}
302305
return slug;
@@ -945,8 +948,8 @@ module.exports = {
945948
// ONE punctuation character normally forbidden in slugs may
946949
// optionally be permitted by specifying it via options.allow.
947950
// The separator may be changed via options.separator.
948-
// By default, accents are preserved. To strip accents,
949-
// set options.stripAccents to true.
951+
// By default, the i18n.options.stripUrlAccents option is honored;
952+
// having stripAccents passed as an option takes precedence.
950953
slugify: function(string, options) {
951954
return self.slugify(string, options);
952955
},

0 commit comments

Comments
 (0)