diff --git a/app.vue b/app.vue index c47dbaa..b7594fa 100644 --- a/app.vue +++ b/app.vue @@ -1,14 +1,9 @@ \ No newline at end of file diff --git a/db.sqlite b/db.sqlite index f6a4ceb..3f20193 100644 Binary files a/db.sqlite and b/db.sqlite differ diff --git a/layouts/default.vue b/layouts/default.vue index 91a022d..ce7fe6c 100644 --- a/layouts/default.vue +++ b/layouts/default.vue @@ -17,7 +17,7 @@

Copyright Peaceultime - 2024

-
+
\ No newline at end of file diff --git a/layouts/explorer.vue b/layouts/explorer.vue index 9f8ef56..00558de 100644 --- a/layouts/explorer.vue +++ b/layouts/explorer.vue @@ -19,7 +19,7 @@

Copyright Peaceultime - 2024

-
+
\ No newline at end of file diff --git a/nuxt.config.ts b/nuxt.config.ts index b707e06..77e65d4 100644 --- a/nuxt.config.ts +++ b/nuxt.config.ts @@ -9,6 +9,7 @@ export default defineNuxtConfig({ } }, tailwindcss: { + viewer: false, config: { theme: { extend: { diff --git a/server/tasks/sync.ts b/server/tasks/sync.ts index 89eddc0..ecec8b0 100644 --- a/server/tasks/sync.ts +++ b/server/tasks/sync.ts @@ -1,8 +1,10 @@ import useDatabase from "~/composables/useDatabase"; import { extname, basename } from 'node:path'; -import type { File } from '~/types/api'; +import type { File, FileType } from '~/types/api'; +import { InputTypeHTMLAttribute } from "vue"; +import { CanvasColor, CanvasContent } from "~/types/canvas"; -const typeMapping: Record = { +const typeMapping: Record = { ".md": "Markdown", ".canvas": "Canvas" } @@ -36,7 +38,7 @@ export default defineTask({ order: order && order[1] ? order[1] : 50, title: order && order[2] ? order[2] : title, type: 'Folder', - content: undefined + content: null } } @@ -44,13 +46,14 @@ export default defineTask({ const title = basename(e.path, extension); const order = /(\d+)\. ?(.+)/gsmi.exec(title); const path = (e.path as string).split('/').map(f => { const check = /(\d+)\. ?(.+)/gsmi.exec(f); return check && check[2] ? check[2] : f }).join('/'); + const content = (await $fetch(`https://git.peaceultime.com/api/v1/repos/peaceultime/system-aspect/raw/${encodeURIComponent(e.path)}`)); return { path: (extension === '.md' ? path.replace(extension, '') : path).toLowerCase().replaceAll(" ", "-").normalize("NFD").replace(/[\u0300-\u036f]/g, ""), order: order && order[1] ? order[1] : 50, title: order && order[2] ? order[2] : title, type: (typeMapping[extension] ?? 'File'), - content: await $fetch(`https://git.peaceultime.com/api/v1/repos/peaceultime/system-aspect/raw/${encodeURIComponent(e.path)}`) + content: reshapeContent(content as string, typeMapping[extension] ?? 'File') } })); @@ -100,4 +103,37 @@ export default defineTask({ return { result: false }; } }, -}) \ No newline at end of file +}) + +function reshapeContent(content: string, type: FileType): string | null +{ + switch(type) + { + case "Markdown": + case "File": + return content; + case "Canvas": + const data = JSON.parse(content) as CanvasContent; + data.edges.forEach(e => e.color = typeof e.color === 'string' ? getColor(e.color) : undefined); + data.nodes.forEach(e => e.color = typeof e.color === 'string' ? getColor(e.color) : undefined); + return JSON.stringify(data); + default: + case 'Folder': + return null; + } +} +function getColor(color: string): CanvasColor +{ + const colors: Record = { + '1': 'fill-light-red dark:fill-dark-red stroke-light-red dark:stroke-dark-red', + '2': 'fill-light-orange dark:fill-dark-orange stroke-light-orange dark:stroke-dark-orange', + '3': 'fill-light-yellow dark:fill-dark-yellow stroke-light-yellow dark:stroke-dark-yellow', + '4': 'fill-light-green dark:fill-dark-green stroke-light-green dark:stroke-dark-green', + '5': 'fill-light-cyan dark:fill-dark-cyan stroke-light-cyan dark:stroke-dark-cyan', + '6': 'fill-light-purple dark:fill-dark-purple stroke-light-purple dark:stroke-dark-purple', + }; + if(colors.hasOwnProperty(color)) + return { class: colors[color] }; + else + return { hex: color }; +} \ No newline at end of file diff --git a/types/canvas.d.ts b/types/canvas.d.ts index 9a448ca..a126928 100644 --- a/types/canvas.d.ts +++ b/types/canvas.d.ts @@ -3,6 +3,11 @@ export interface CanvasContent { edges: CanvasEdge[]; groups: CanvasGroup[]; } +export type CanvasColor = { + class?: string; +} & { + hex?: string; +} export interface CanvasNode { type: 'group' | 'text'; id: string; @@ -10,7 +15,7 @@ export interface CanvasNode { y: number; width: number; height: number; - color?: string; + color?: CanvasColor; label?: string; text?: any; }; @@ -20,7 +25,7 @@ export interface CanvasEdge { fromSide: 'bottom' | 'top' | 'left' | 'right'; toNode: string; toSide: 'bottom' | 'top' | 'left' | 'right'; - color?: string; + color?: CanvasColor; label?: string; }; export interface CanvasGroup {