@@ -86,26 +86,6 @@ async function renderURL(context: Context, options: PfeDevServerInternalConfig):
8686 }
8787}
8888
89- function kebabCase ( string : string ) {
90- return string
91- . replace ( / [ ^ a - z A - Z 0 - 9 \s ] / g, '' ) // Remove all characters not letters, numbers or spaces
92- . replace ( / [ \s _ ] + / g, '-' ) // Replace spaces and underscores with -
93- . replace ( / - + / g, '-' ) // Replace multiple - with single -
94- . replace ( / ^ - + | - + $ / g, '' ) // Remove leading and trailing -
95- . toLowerCase ( ) ;
96- }
97-
98- function convertAliases ( aliases : Record < string , string > ) {
99- const keyedAliases = { } as Record < string , string > ;
100- for ( const key in aliases ) {
101- if ( { } . hasOwnProperty . call ( aliases , key ) ) {
102- const newKey = kebabCase ( aliases [ key ] ) ;
103- keyedAliases [ newKey ] = key ;
104- }
105- }
106- return keyedAliases ;
107- }
108-
10989/**
11090 * Generate HTML for each component by rendering a nunjucks template
11191 * Watch repository source files and reload the page when they change
@@ -117,15 +97,6 @@ function pfeDevServerPlugin(options: PfeDevServerInternalConfig): Plugin {
11797 const { elementsDir, tagPrefix, aliases } = options ;
11898 const { componentSubpath } = options . site ;
11999
120- const keyedAliases = convertAliases ( aliases ) ;
121-
122- const prefixTag = ( tag : string ) => {
123- if ( ! tag . startsWith ( tagPrefix ) ) {
124- return `${ tagPrefix } -${ tag } ` ;
125- }
126- return tag ;
127- } ;
128-
129100 const router =
130101 new Router ( )
131102 . get ( / \/ p f - i c o n \/ i c o n s \/ .* \. j s $ / , ( ctx , next ) => {
@@ -139,25 +110,22 @@ function pfeDevServerPlugin(options: PfeDevServerInternalConfig): Plugin {
139110 // Redirect `components/jazz-hands/*.js` to `components/pf-jazz-hands/*.ts`
140111 . get ( `/${ componentSubpath } /:element/:fileName.js` , async ctx => {
141112 const { element, fileName } = ctx . params ;
142-
143- const prefixedElement = keyedAliases [ element ] ?? prefixTag ( element ) ;
113+ const prefixedElement = deslugify ( element ) ;
144114
145115 ctx . redirect ( `/${ elementsDir } /${ prefixedElement } /${ fileName } .ts` ) ;
146116 } )
147117 // Redirect `elements/jazz-hands/*.js` to `elements/pf-jazz-hands/*.ts`
148118 . get ( `/${ elementsDir } /:element/:fileName.js` , async ctx => {
149119 const { element, fileName } = ctx . params ;
150-
151- const prefixedElement = keyedAliases [ element ] ?? prefixTag ( element ) ;
120+ const prefixedElement = deslugify ( element ) ;
152121
153122 ctx . redirect ( `/${ elementsDir } /${ prefixedElement } /${ fileName } .ts` ) ;
154123 } )
155124 // Redirect `components/pf-jazz-hands|jazz-hands/demo/*-lightdom.css` to `components/pf-jazz-hands/*-lightdom.css`
156125 // Redirect `components/jazz-hands/demo/*.js|css` to `components/pf-jazz-hands/demo/*.js|css`
157126 . get ( `/${ componentSubpath } /:element/demo/:demoSubDir?/:fileName.:ext` , async ( ctx , next ) => {
158127 const { element, fileName, ext } = ctx . params ;
159-
160- const prefixedElement = keyedAliases [ element ] ?? prefixTag ( element ) ;
128+ const prefixedElement = deslugify ( element ) ;
161129
162130 if ( fileName . includes ( '-lightdom' ) && ext === 'css' ) {
163131 ctx . redirect ( `/${ elementsDir } /${ prefixedElement } /${ fileName } .${ ext } ` ) ;
@@ -170,12 +138,14 @@ function pfeDevServerPlugin(options: PfeDevServerInternalConfig): Plugin {
170138 // Redirect `components/jazz-hands/*` to `components/pf-jazz-hands/*` for requests not previously handled
171139 . get ( `/${ componentSubpath } /:element/:splatPath*` , async ( ctx , next ) => {
172140 const { element, splatPath } = ctx . params ;
141+ const prefixedElement = deslugify ( element ) ;
142+
173143 if ( splatPath . includes ( 'demo' ) ) {
174144 /* if its the demo directory return */
175145 return next ( ) ;
176146 }
177147 if ( ! element . includes ( tagPrefix ) ) {
178- ctx . redirect ( `/${ elementsDir } /${ tagPrefix } - ${ element } /${ splatPath } ` ) ;
148+ ctx . redirect ( `/${ elementsDir } /${ prefixedElement } /${ splatPath } ` ) ;
179149 } else {
180150 return next ( ) ;
181151 }
0 commit comments