Skip to content

Commit 6a3aefb

Browse files
committed
refactor: move slugify function from conde injector to config validator
1 parent a61140d commit 6a3aefb

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

adminforth/modules/codeInjector.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,6 @@ class CodeInjector implements ICodeInjector {
331331
if (page.icon) {
332332
icons.push(page.icon);
333333
}
334-
page.slug = page.slug ?? slugifyString(page.pageLabel);
335334
}
336335
}
337336

adminforth/modules/configValidator.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717

1818
import fs from 'fs';
1919
import path from 'path';
20-
import { guessLabelFromName, md5hash, suggestIfTypo } from './utils.js';
20+
import { guessLabelFromName, md5hash, suggestIfTypo, slugifyString } from './utils.js';
2121
import {
2222
AdminForthSortDirections,
2323
type AdminForthComponentDeclarationFull,
@@ -30,7 +30,6 @@ import AdminForth from "adminforth";
3030
import { AdminForthConfigMenuItem } from "adminforth";
3131

3232

33-
3433
export default class ConfigValidator implements IConfigValidator {
3534

3635
customComponentsDir: string | undefined;
@@ -169,9 +168,8 @@ export default class ConfigValidator implements IConfigValidator {
169168
}
170169

171170
// slug should have only lowercase letters, dashes and numbers
172-
customization.brandNameSlug = customization.brandName.toLowerCase().replace(/[^a-z0-9-]/g, '');
171+
customization.brandNameSlug = slugifyString(customization.brandName);
173172

174-
175173
if (customization.brandLogo) {
176174
errors.push(...this.checkCustomFileExists(customization.brandLogo));
177175
}
@@ -1002,6 +1000,7 @@ export default class ConfigValidator implements IConfigValidator {
10021000
if (newConfig.auth.userMenuSettingsPages) {
10031001
for (const page of newConfig.auth.userMenuSettingsPages) {
10041002
this.validateComponent({file: page.component}, errors);
1003+
page.slug = page.slug ?? slugifyString(page.pageLabel);
10051004
}
10061005
}
10071006

0 commit comments

Comments
 (0)