Skip to content

Commit 36816ea

Browse files
authored
Merge pull request #223 from laurenskling/feature/slugify
allow to override the slugify function
2 parents f0c87b2 + 44f8d18 commit 36816ea

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

packages/core/server/config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
import deburr from 'lodash/deburr';
2+
import toLower from 'lodash/toLower';
3+
import kebabCase from 'lodash/kebabCase';
4+
15
export interface Config {
26
website_url: string;
37
default_pattern: string,
8+
slugify: (fieldValue: string) => string
49
}
510

611
const config: {
@@ -10,6 +15,7 @@ const config: {
1015
default: {
1116
website_url: null,
1217
default_pattern: '/[pluralName]/[documentId]',
18+
slugify: (fieldValue) => kebabCase(deburr(toLower(fieldValue))),
1319
},
1420
validator() {},
1521
};

packages/core/server/services/url-pattern.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import { factories, Schema, UID } from '@strapi/strapi';
2-
import deburr from 'lodash/deburr';
3-
import toLower from 'lodash/toLower';
4-
import kebabCase from 'lodash/kebabCase';
52
import { getPluginService } from '../util/getPluginService';
63
import { typedEntries } from '../util/typeHelpers';
4+
import { Config } from '../config';
75

86
const contentTypeSlug = 'plugin::webtools.url-pattern';
97

@@ -171,8 +169,8 @@ const customServices = () => ({
171169

172170
resolvedPattern = resolvedPattern.replace(`[${field}]`, fieldValue || '');
173171
} else if (!relationalField) {
174-
// Slugify the field value
175-
const fieldValue = kebabCase(deburr(toLower(String(entity[field]))));
172+
const { slugify } = strapi.config.get<Config>('plugin::webtools');
173+
const fieldValue = slugify(String(entity[field]));
176174
resolvedPattern = resolvedPattern.replace(`[${field}]`, fieldValue || '');
177175
} else if (Array.isArray(entity[relationalField[0]])) {
178176
strapi.log.error('Something went wrong whilst resolving the pattern.');

0 commit comments

Comments
 (0)