Categorize routes

This commit is contained in:
Nicola Spadari
2025-02-26 15:26:42 +01:00
parent 2afee8254b
commit 8f5efa0a17
8 changed files with 52 additions and 14 deletions

View File

@@ -13,6 +13,7 @@
variant="link" variant="link"
:ui="{ :ui="{
root: 'hidden md:flex', root: 'hidden md:flex',
viewportWrapper: 'max-w-2xl absolute-center-h',
list: 'md:gap-x-2' list: 'md:gap-x-2'
}" }"
/> />

View File

@@ -1,13 +1,32 @@
export const usePages = () => { export const usePages = () => {
const router = useRouter(); const router = useRouter();
const pages = router.getRoutes().filter((route) => route.name !== "index" && route.name !== "all").map((route) => { const routes = router.getRoutes().filter((route) => route.name !== "index" && route.name !== "all");
return {
label: route.meta.name, const categorizedRoutes = routes.reduce((acc, route) => {
to: route.path, const category = route.meta.category as string;
icon: route.meta.icon if (!category) return acc;
};
}); if (!acc[category]) {
acc[category] = {
label: category.charAt(0).toUpperCase() + category.slice(1),
icon: route.meta.categoryIcon || "i-lucide-folder",
to: route.path,
children: []
};
}
acc[category].children.push({
label: route.meta.name as string,
description: route.meta.description as string,
icon: `i-${route.meta.icon}`,
to: route.path
});
return acc;
}, {} as Record<string, any>);
const pages = Object.values(categorizedRoutes);
return { return {
pages pages

View File

@@ -25,8 +25,11 @@
<script lang="ts" setup> <script lang="ts" setup>
definePageMeta({ definePageMeta({
name: "Commands", name: "Shell commands",
icon: "lucide:square-terminal" icon: "lucide:terminal",
description: "Execute shell commands",
category: "system",
categoryIcon: "lucide:square-terminal"
}); });
const schema = z.object({ const schema = z.object({

View File

@@ -22,7 +22,10 @@
<script lang="ts" setup> <script lang="ts" setup>
definePageMeta({ definePageMeta({
name: "Files", name: "Files",
icon: "lucide:file-text" icon: "lucide:file-text",
category: "storage",
categoryIcon: "lucide:database",
description: "Create and manage files"
}); });
const schema = z.object({ const schema = z.object({

View File

@@ -22,7 +22,10 @@
<script lang="ts" setup> <script lang="ts" setup>
definePageMeta({ definePageMeta({
name: "Notifications", name: "Notifications",
icon: "lucide:message-square-more" icon: "lucide:message-square-more",
category: "interface",
categoryIcon: "lucide:app-window-mac",
description: "Send native notifications"
}); });
const schema = z.object({ const schema = z.object({

View File

@@ -10,7 +10,10 @@
<script lang="ts" setup> <script lang="ts" setup>
definePageMeta({ definePageMeta({
name: "OS Informations", name: "OS Informations",
icon: "lucide:info" icon: "lucide:info",
category: "system",
categoryIcon: "lucide:square-terminal",
description: "Read operating system informations."
}); });
const items = ref([ const items = ref([

View File

@@ -26,7 +26,10 @@
<script lang="ts" setup> <script lang="ts" setup>
definePageMeta({ definePageMeta({
name: "Store", name: "Store",
icon: "lucide:database" icon: "lucide:database",
category: "storage",
categoryIcon: "lucide:database",
description: "Handle file creation in the file system"
}); });
const schema = z.object({ const schema = z.object({

View File

@@ -17,7 +17,10 @@
<script lang="ts" setup> <script lang="ts" setup>
definePageMeta({ definePageMeta({
name: "Webview", name: "Webview",
icon: "lucide:app-window-mac" icon: "lucide:app-window-mac",
category: "interface",
categoryIcon: "lucide:app-window-mac",
description: "Create new webview in a detached window"
}); });
const { app } = useAppConfig(); const { app } = useAppConfig();