-
Notifications
You must be signed in to change notification settings - Fork 1
feature/ ability to add spaces in menu #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,20 +11,28 @@ const pages = import.meta.glob<{ default: React.ComponentType }>( | |
| "../pages/*.tsx", | ||
| ); | ||
|
|
||
| const splitFirst = (str: string, separator: string): [string | null, string] => { | ||
| const index = str.indexOf(separator); | ||
| if (index === -1) { | ||
| return [null, str]; | ||
| } | ||
| return [str.slice(0, index), str.slice(index + 1)]; | ||
| }; | ||
|
|
||
|
|
||
| export const routes = Object.keys(pages) | ||
| .filter((path) => !path.includes("_components")) | ||
| .map((path) => { | ||
| const fullFileName = path.split("/").pop()?.replace(".tsx", "") || ""; | ||
| const hasPrefix = fullFileName.includes("_"); | ||
| const prefix = hasPrefix ? fullFileName.split("_")[0] : null; | ||
| const cleanName = hasPrefix ? fullFileName.split("_")[1] : fullFileName; | ||
| const [prefix, cleanName] = splitFirst(fullFileName, "_"); | ||
| const menuName = cleanName.replaceAll("_", " "); | ||
|
||
|
|
||
| const routePath = | ||
| cleanName.toLowerCase() === "app" ? "/" : `/${cleanName.toLowerCase()}`; | ||
|
|
||
| return { | ||
| path: routePath, | ||
| name: cleanName, | ||
| name: menuName, | ||
|
||
| prefix: prefix, | ||
| component: React.lazy(() => pages[path]()), | ||
| }; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
splitFirsttakes a genericseparator: string, but slices usingindex + 1. Ifseparatorever becomes longer than 1 character this will produce incorrect results; usingindex + separator.length(or constrainingseparatorto a single character) would make the helper consistent with its signature.