File tree 4 files changed +17
-2
lines changed
4 files changed +17
-2
lines changed Original file line number Diff line number Diff line change 36
36
"netlify-cms-ui-default" : " ^2.12.2" ,
37
37
"react" : " ^16.8.4" ,
38
38
"react-dom" : " ^16.8.4" ,
39
- "react-select" : " ^3.1.0"
39
+ "react-select" : " ^3.1.0" ,
40
+ "slugify" : " ^1.5.0"
40
41
},
41
42
"devDependencies" : {
42
43
"@babel/core" : " ^7.11.6" ,
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import React from 'react';
2
2
import AsyncSelect from 'react-select/async' ;
3
3
import { reactSelectStyles } from 'netlify-cms-ui-default/dist/esm/styles' ;
4
4
import { NestedCollection } from './NestedCollection' ;
5
+ import slugify from 'slugify' ;
5
6
6
7
const trimStart = ( str , prefix ) => {
7
8
return str . substring ( prefix . length ) ;
@@ -44,7 +45,7 @@ const Option = (props) => {
44
45
45
46
export const sanitizePath = ( path ) => {
46
47
const replacement = '-' ;
47
- const sanitizedPath = path . replace ( / [ ^ a - z 0 - 9 ] / gi , replacement ) . toLowerCase ( ) ;
48
+ const sanitizedPath = slugify ( path . toLowerCase ( ) , replacement ) ;
48
49
49
50
// Remove any doubled or leading/trailing replacement characters (that were added in the sanitizers).
50
51
const doubleReplacement = new RegExp ( `(?:${ replacement } )+` , 'g' ) ;
Original file line number Diff line number Diff line change @@ -20,4 +20,12 @@ describe('sanitizePath', () => {
20
20
it ( 'should remove double replacer' , ( ) => {
21
21
expect ( sanitizePath ( 'Who Are We' ) ) . toBe ( 'who-are-we' ) ;
22
22
} ) ;
23
+
24
+ it ( 'should keep diacritis' , ( ) => {
25
+ expect ( sanitizePath ( 'ăștia sunteți voi' ) ) . toBe ( 'astia-sunteti-voi' ) ;
26
+ } ) ;
27
+
28
+ it ( 'should keep diacritis and remove whitespace, trailing and leading characters' , ( ) => {
29
+ expect ( sanitizePath ( '?ăștia sunteți voi ? ' ) ) . toBe ( 'astia-sunteti-voi' ) ;
30
+ } ) ;
23
31
} ) ;
Original file line number Diff line number Diff line change @@ -7015,6 +7015,11 @@ slice-ansi@^4.0.0:
7015
7015
astral-regex "^2.0.0"
7016
7016
is-fullwidth-code-point "^3.0.0"
7017
7017
7018
+ slugify@^1.5.0 :
7019
+ version "1.5.0"
7020
+ resolved "https://registry.yarnpkg.com/slugify/-/slugify-1.5.0.tgz#5f3c8e2a84105b54eb51486db1b468a599b3c9b8"
7021
+ integrity sha512-Q2UPZ2udzquy1ElHfOLILMBMqBEXkiD3wE75qtBvV+FsDdZZjUqPZ44vqLTejAVq+wLLHacOMcENnP8+ZbzmIA==
7022
+
7018
7023
snapdragon-node@^2.0.1 :
7019
7024
version "2.1.1"
7020
7025
resolved "https://registry.yarnpkg.com/snapdragon-node/-/snapdragon-node-2.1.1.tgz#6c175f86ff14bdb0724563e8f3c1b021a286853b"
You can’t perform that action at this time.
0 commit comments