diff --git a/.gitignore b/.gitignore index afa9c3d..ffcba71 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,6 @@ # generated -public/images/projects - -# temporary -__old +public/images/projects/pokemons +app/composables/useAssets.ts # ESlint .eslintcache diff --git a/app/components/Common/ButtonSelector.vue b/app/components/Common/ButtonSelector.vue index 5dd9b61..564ad31 100644 --- a/app/components/Common/ButtonSelector.vue +++ b/app/components/Common/ButtonSelector.vue @@ -1,6 +1,4 @@ + + diff --git a/app/stores/projects.ts b/app/stores/projects.ts index 0ae0fb2..2843842 100644 --- a/app/stores/projects.ts +++ b/app/stores/projects.ts @@ -38,7 +38,9 @@ export const useProjectsStore = defineStore("projects", { if (!projects.value) throw "Cannot load projects"; this.projects = projects.value.map((project) => ({ ...project, - id: project.id.split("/")[2]!, + id: project.id + .split("/")[2]! + .replace(/-([a-z])/g, (_, letter) => letter.toUpperCase()), })); console.log(this.projects); diff --git a/modules/content-assets.ts b/modules/content-assets.ts index 008e149..d7184f8 100644 --- a/modules/content-assets.ts +++ b/modules/content-assets.ts @@ -13,7 +13,10 @@ export default defineNuxtModule({ async setup(_, nuxt) { const logger = useLogger("content-assets"); const contentDir = join(nuxt.options.rootDir, "content"); - const publicDir = join(nuxt.options.rootDir, "public/images/projects"); + const publicDir = join( + nuxt.options.rootDir, + "public/images/projects/pokemons", + ); const getFileChecksum = async (filePath: string): Promise => { const content = await readFile(filePath); diff --git a/modules/image-assets.ts b/modules/image-assets.ts new file mode 100644 index 0000000..4e7697b --- /dev/null +++ b/modules/image-assets.ts @@ -0,0 +1,128 @@ +import { defineNuxtModule, useLogger } from "@nuxt/kit"; +import { readdir, readFile, writeFile } from "fs/promises"; +import { join, relative, parse } from "path"; +import { existsSync, watch } from "fs"; + +type AssetsTree = { + [key: string]: string | AssetsTree; +}; + +const IMAGE_EXTENSIONS = new Set([".png", ".jpg", ".jpeg", ".webp", ".gif"]); + +export default defineNuxtModule({ + meta: { + name: "image-assets", + configKey: "imageAssets", + }, + defaults: {}, + async setup(_, nuxt) { + const logger = useLogger("image-assets"); + const publicImagesDir = join(nuxt.options.rootDir, "public/images"); + const templateFile = join( + nuxt.options.rootDir, + "app/composables/useAssets.ts.in", + ); + const outputFile = join( + nuxt.options.rootDir, + "app/composables/useAssets.ts", + ); + + const isImageFile = (filename: string): boolean => { + const ext = parse(filename).ext.toLowerCase(); + return IMAGE_EXTENSIONS.has(ext); + }; + + const scanDirectory = async (dir: string): Promise => { + const images: string[] = []; + const entries = await readdir(dir, { withFileTypes: true }); + + for (const entry of entries) { + const fullPath = join(dir, entry.name); + if (entry.isDirectory()) { + images.push(...(await scanDirectory(fullPath))); + } else if (isImageFile(entry.name)) { + images.push(fullPath); + } + } + + return images; + }; + + const toCamelCase = (str: string): string => { + return str.replace(/[-_](.)/g, (_, c) => c.toUpperCase()); + }; + + const buildAssetsTree = (images: string[], baseDir: string): AssetsTree => { + const tree: AssetsTree = {}; + + for (const imagePath of images) { + const relativePath = relative(baseDir, imagePath); + const parts = relativePath.split("/"); + const filename = parse(parts[parts.length - 1]!).name; + + let current = tree; + for (let i = 0; i < parts.length - 1; i += 1) { + const key = toCamelCase(parts[i]!); + current[key] ??= {}; + current = current[key] as AssetsTree; + } + + current[toCamelCase(filename)] = `/images/${relativePath}`; + } + + return tree; + }; + + const generateAssetsObject = (tree: AssetsTree, indent = 0): string => { + const spaces = " ".repeat(indent); + const entries = Object.entries(tree); + if (!entries.length) return "{}"; + + const lines = entries.map(([key, value]) => + typeof value === "string" + ? `${spaces} ${key}: createImage("${value}"),` + : `${spaces} ${key}: ${generateAssetsObject(value, indent + 1)},`, + ); + + return `{\n${lines.join("\n")}\n${spaces}}`; + }; + + const generateAssetsFile = async () => { + try { + if (!existsSync(publicImagesDir)) { + logger.warn("No public/images directory found"); + return; + } + + const images = await scanDirectory(publicImagesDir); + const assetsTree = buildAssetsTree(images, publicImagesDir); + const assetsObject = generateAssetsObject(assetsTree); + + const template = await readFile(templateFile, "utf-8"); + const fileContent = template + .replace("{{TOTAL}}", images.length.toString()) + .replace("{{ASSETS}}", assetsObject); + + await writeFile(outputFile, fileContent, "utf-8"); + logger.success(`Generated useAssets.ts with ${images.length} images`); + } catch (error) { + logger.error("Error generating assets file:", error); + } + }; + + nuxt.hook("build:before", async () => { + await generateAssetsFile(); + }); + + if (nuxt.options.dev) { + nuxt.hook("ready", () => { + watch(publicImagesDir, { recursive: true }, async (_, filePath) => { + if (filePath && isImageFile(filePath)) { + logger.info(`Detected change: ${filePath}`); + await generateAssetsFile(); + } + }); + }); + } + }, +}); diff --git a/nuxt.config.ts b/nuxt.config.ts index 7fda4be..f8aa02d 100644 --- a/nuxt.config.ts +++ b/nuxt.config.ts @@ -7,6 +7,7 @@ export default defineNuxtConfig({ "@nuxt/content", "@pinia/nuxt", "./modules/content-assets", + "./modules/image-assets", "@nuxtjs/i18n", "@tresjs/nuxt", ], diff --git a/app/assets/images/contact/bottom-screen/background.webp b/public/images/contact/bottom-screen/background.webp similarity index 100% rename from app/assets/images/contact/bottom-screen/background.webp rename to public/images/contact/bottom-screen/background.webp diff --git a/app/assets/images/contact/bottom-screen/bottom-bar.webp b/public/images/contact/bottom-screen/bottom-bar.webp similarity index 100% rename from app/assets/images/contact/bottom-screen/bottom-bar.webp rename to public/images/contact/bottom-screen/bottom-bar.webp diff --git a/app/assets/images/contact/bottom-screen/buttons.webp b/public/images/contact/bottom-screen/buttons.webp similarity index 100% rename from app/assets/images/contact/bottom-screen/buttons.webp rename to public/images/contact/bottom-screen/buttons.webp diff --git a/app/assets/images/contact/bottom-screen/notification.webp b/public/images/contact/bottom-screen/notification.webp similarity index 100% rename from app/assets/images/contact/bottom-screen/notification.webp rename to public/images/contact/bottom-screen/notification.webp diff --git a/app/assets/images/contact/bottom-screen/ok-button.webp b/public/images/contact/bottom-screen/ok-button.webp similarity index 100% rename from app/assets/images/contact/bottom-screen/ok-button.webp rename to public/images/contact/bottom-screen/ok-button.webp diff --git a/app/assets/images/contact/bottom-screen/top-bar.webp b/public/images/contact/bottom-screen/top-bar.webp similarity index 100% rename from app/assets/images/contact/bottom-screen/top-bar.webp rename to public/images/contact/bottom-screen/top-bar.webp diff --git a/app/assets/images/contact/top-screen/background.webp b/public/images/contact/top-screen/background.webp similarity index 100% rename from app/assets/images/contact/top-screen/background.webp rename to public/images/contact/top-screen/background.webp diff --git a/app/assets/images/contact/top-screen/left-bar-things.webp b/public/images/contact/top-screen/left-bar-things.webp similarity index 100% rename from app/assets/images/contact/top-screen/left-bar-things.webp rename to public/images/contact/top-screen/left-bar-things.webp diff --git a/app/assets/images/contact/top-screen/left-bar.webp b/public/images/contact/top-screen/left-bar.webp similarity index 100% rename from app/assets/images/contact/top-screen/left-bar.webp rename to public/images/contact/top-screen/left-bar.webp diff --git a/app/assets/images/contact/top-screen/title.webp b/public/images/contact/top-screen/title.webp similarity index 100% rename from app/assets/images/contact/top-screen/title.webp rename to public/images/contact/top-screen/title.webp diff --git a/app/assets/images/home/bottom-screen/background.webp b/public/images/home/bottom-screen/background.webp similarity index 100% rename from app/assets/images/home/bottom-screen/background.webp rename to public/images/home/bottom-screen/background.webp diff --git a/app/assets/images/home/bottom-screen/buttons/alarm.webp b/public/images/home/bottom-screen/buttons/alarm.webp similarity index 100% rename from app/assets/images/home/bottom-screen/buttons/alarm.webp rename to public/images/home/bottom-screen/buttons/alarm.webp diff --git a/app/assets/images/home/bottom-screen/buttons/contact.webp b/public/images/home/bottom-screen/buttons/contact.webp similarity index 100% rename from app/assets/images/home/bottom-screen/buttons/contact.webp rename to public/images/home/bottom-screen/buttons/contact.webp diff --git a/app/assets/images/home/bottom-screen/buttons/corner.webp b/public/images/home/bottom-screen/buttons/corner.webp similarity index 100% rename from app/assets/images/home/bottom-screen/buttons/corner.webp rename to public/images/home/bottom-screen/buttons/corner.webp diff --git a/app/assets/images/home/bottom-screen/buttons/downloadPlay.webp b/public/images/home/bottom-screen/buttons/downloadPlay.webp similarity index 100% rename from app/assets/images/home/bottom-screen/buttons/downloadPlay.webp rename to public/images/home/bottom-screen/buttons/downloadPlay.webp diff --git a/app/assets/images/home/bottom-screen/buttons/game.webp b/public/images/home/bottom-screen/buttons/game.webp similarity index 100% rename from app/assets/images/home/bottom-screen/buttons/game.webp rename to public/images/home/bottom-screen/buttons/game.webp diff --git a/app/assets/images/home/bottom-screen/buttons/settings.webp b/public/images/home/bottom-screen/buttons/settings.webp similarity index 100% rename from app/assets/images/home/bottom-screen/buttons/settings.webp rename to public/images/home/bottom-screen/buttons/settings.webp diff --git a/app/assets/images/home/bottom-screen/buttons/theme.webp b/public/images/home/bottom-screen/buttons/theme.webp similarity index 100% rename from app/assets/images/home/bottom-screen/buttons/theme.webp rename to public/images/home/bottom-screen/buttons/theme.webp diff --git a/app/assets/images/home/top-screen/background.webp b/public/images/home/top-screen/background.webp similarity index 100% rename from app/assets/images/home/top-screen/background.webp rename to public/images/home/top-screen/background.webp diff --git a/app/assets/images/home/top-screen/calendar/calendar.webp b/public/images/home/top-screen/calendar/calendar.webp similarity index 100% rename from app/assets/images/home/top-screen/calendar/calendar.webp rename to public/images/home/top-screen/calendar/calendar.webp diff --git a/app/assets/images/home/top-screen/calendar/day-selector.webp b/public/images/home/top-screen/calendar/day-selector.webp similarity index 100% rename from app/assets/images/home/top-screen/calendar/day-selector.webp rename to public/images/home/top-screen/calendar/day-selector.webp diff --git a/app/assets/images/home/top-screen/calendar/last-row.webp b/public/images/home/top-screen/calendar/last-row.webp similarity index 100% rename from app/assets/images/home/top-screen/calendar/last-row.webp rename to public/images/home/top-screen/calendar/last-row.webp diff --git a/app/assets/images/home/top-screen/clock.webp b/public/images/home/top-screen/clock.webp similarity index 100% rename from app/assets/images/home/top-screen/clock.webp rename to public/images/home/top-screen/clock.webp diff --git a/app/assets/images/home/top-screen/status-bar/battery.webp b/public/images/home/top-screen/status-bar/battery.webp similarity index 100% rename from app/assets/images/home/top-screen/status-bar/battery.webp rename to public/images/home/top-screen/status-bar/battery.webp diff --git a/app/assets/images/home/top-screen/status-bar/gba-display.webp b/public/images/home/top-screen/status-bar/gba-display.webp similarity index 100% rename from app/assets/images/home/top-screen/status-bar/gba-display.webp rename to public/images/home/top-screen/status-bar/gba-display.webp diff --git a/app/assets/images/home/top-screen/status-bar/startup-mode.webp b/public/images/home/top-screen/status-bar/startup-mode.webp similarity index 100% rename from app/assets/images/home/top-screen/status-bar/startup-mode.webp rename to public/images/home/top-screen/status-bar/startup-mode.webp diff --git a/app/assets/images/home/top-screen/status-bar/status-bar.webp b/public/images/home/top-screen/status-bar/status-bar.webp similarity index 100% rename from app/assets/images/home/top-screen/status-bar/status-bar.webp rename to public/images/home/top-screen/status-bar/status-bar.webp diff --git a/public/images/projects/biobleud.webp b/public/images/projects/biobleud.webp new file mode 100644 index 0000000..74a2946 Binary files /dev/null and b/public/images/projects/biobleud.webp differ diff --git a/app/assets/images/projects/bottom-screen/background.webp b/public/images/projects/bottom-screen/background.webp similarity index 100% rename from app/assets/images/projects/bottom-screen/background.webp rename to public/images/projects/bottom-screen/background.webp diff --git a/app/assets/images/projects/bottom-screen/circle_big.webp b/public/images/projects/bottom-screen/circle_big.webp similarity index 100% rename from app/assets/images/projects/bottom-screen/circle_big.webp rename to public/images/projects/bottom-screen/circle_big.webp diff --git a/app/assets/images/projects/bottom-screen/circle_small.webp b/public/images/projects/bottom-screen/circle_small.webp similarity index 100% rename from app/assets/images/projects/bottom-screen/circle_small.webp rename to public/images/projects/bottom-screen/circle_small.webp diff --git a/app/assets/images/projects/bottom-screen/link-pressed.webp b/public/images/projects/bottom-screen/link-pressed.webp similarity index 100% rename from app/assets/images/projects/bottom-screen/link-pressed.webp rename to public/images/projects/bottom-screen/link-pressed.webp diff --git a/app/assets/images/projects/bottom-screen/next-pressed.webp b/public/images/projects/bottom-screen/next-pressed.webp similarity index 100% rename from app/assets/images/projects/bottom-screen/next-pressed.webp rename to public/images/projects/bottom-screen/next-pressed.webp diff --git a/app/assets/images/projects/bottom-screen/prev-pressed.webp b/public/images/projects/bottom-screen/prev-pressed.webp similarity index 100% rename from app/assets/images/projects/bottom-screen/prev-pressed.webp rename to public/images/projects/bottom-screen/prev-pressed.webp diff --git a/app/assets/images/projects/bottom-screen/quit-pressed.webp b/public/images/projects/bottom-screen/quit-pressed.webp similarity index 100% rename from app/assets/images/projects/bottom-screen/quit-pressed.webp rename to public/images/projects/bottom-screen/quit-pressed.webp diff --git a/public/images/projects/lbf-bot.webp b/public/images/projects/lbf-bot.webp new file mode 100644 index 0000000..870f13e Binary files /dev/null and b/public/images/projects/lbf-bot.webp differ diff --git a/public/images/projects/lilou-cat.webp b/public/images/projects/lilou-cat.webp new file mode 100644 index 0000000..a68c9e2 Binary files /dev/null and b/public/images/projects/lilou-cat.webp differ diff --git a/public/images/projects/pihkaal-me.webp b/public/images/projects/pihkaal-me.webp new file mode 100644 index 0000000..aefcfca Binary files /dev/null and b/public/images/projects/pihkaal-me.webp differ diff --git a/public/images/projects/raylib-speedruns.webp b/public/images/projects/raylib-speedruns.webp new file mode 100644 index 0000000..7317eed Binary files /dev/null and b/public/images/projects/raylib-speedruns.webp differ diff --git a/public/images/projects/s3pweb.webp b/public/images/projects/s3pweb.webp new file mode 100644 index 0000000..5f14ca5 Binary files /dev/null and b/public/images/projects/s3pweb.webp differ diff --git a/public/images/projects/simple-qr.webp b/public/images/projects/simple-qr.webp new file mode 100644 index 0000000..91db7bb Binary files /dev/null and b/public/images/projects/simple-qr.webp differ diff --git a/public/images/projects/tlock.webp b/public/images/projects/tlock.webp new file mode 100644 index 0000000..4438594 Binary files /dev/null and b/public/images/projects/tlock.webp differ diff --git a/app/assets/images/projects/top-screen/background.webp b/public/images/projects/top-screen/background.webp similarity index 100% rename from app/assets/images/projects/top-screen/background.webp rename to public/images/projects/top-screen/background.webp diff --git a/app/assets/images/settings/bottom-screen/bottom-bar.webp b/public/images/settings/bottom-screen/bottom-bar.webp similarity index 100% rename from app/assets/images/settings/bottom-screen/bottom-bar.webp rename to public/images/settings/bottom-screen/bottom-bar.webp diff --git a/app/assets/images/settings/bottom-screen/top-bar.webp b/public/images/settings/bottom-screen/top-bar.webp similarity index 100% rename from app/assets/images/settings/bottom-screen/top-bar.webp rename to public/images/settings/bottom-screen/top-bar.webp diff --git a/app/assets/images/settings/top-screen/clock/alarm.webp b/public/images/settings/top-screen/clock/alarm.webp similarity index 100% rename from app/assets/images/settings/top-screen/clock/alarm.webp rename to public/images/settings/top-screen/clock/alarm.webp diff --git a/app/assets/images/settings/top-screen/clock/clock-active.webp b/public/images/settings/top-screen/clock/clock-active.webp similarity index 100% rename from app/assets/images/settings/top-screen/clock/clock-active.webp rename to public/images/settings/top-screen/clock/clock-active.webp diff --git a/app/assets/images/settings/top-screen/clock/clock-disabled.png b/public/images/settings/top-screen/clock/clock-disabled.png similarity index 100% rename from app/assets/images/settings/top-screen/clock/clock-disabled.png rename to public/images/settings/top-screen/clock/clock-disabled.png diff --git a/app/assets/images/settings/top-screen/clock/clock.webp b/public/images/settings/top-screen/clock/clock.webp similarity index 100% rename from app/assets/images/settings/top-screen/clock/clock.webp rename to public/images/settings/top-screen/clock/clock.webp diff --git a/app/assets/images/settings/top-screen/clock/date.webp b/public/images/settings/top-screen/clock/date.webp similarity index 100% rename from app/assets/images/settings/top-screen/clock/date.webp rename to public/images/settings/top-screen/clock/date.webp diff --git a/app/assets/images/settings/top-screen/clock/time.webp b/public/images/settings/top-screen/clock/time.webp similarity index 100% rename from app/assets/images/settings/top-screen/clock/time.webp rename to public/images/settings/top-screen/clock/time.webp diff --git a/app/assets/images/settings/top-screen/notification.webp b/public/images/settings/top-screen/notification.webp similarity index 100% rename from app/assets/images/settings/top-screen/notification.webp rename to public/images/settings/top-screen/notification.webp diff --git a/app/assets/images/settings/top-screen/options/gba-mode.webp b/public/images/settings/top-screen/options/gba-mode.webp similarity index 100% rename from app/assets/images/settings/top-screen/options/gba-mode.webp rename to public/images/settings/top-screen/options/gba-mode.webp diff --git a/app/assets/images/settings/top-screen/options/language.webp b/public/images/settings/top-screen/options/language.webp similarity index 100% rename from app/assets/images/settings/top-screen/options/language.webp rename to public/images/settings/top-screen/options/language.webp diff --git a/app/assets/images/settings/top-screen/options/options-active.png b/public/images/settings/top-screen/options/options-active.png similarity index 100% rename from app/assets/images/settings/top-screen/options/options-active.png rename to public/images/settings/top-screen/options/options-active.png diff --git a/app/assets/images/settings/top-screen/options/options-disabled.png b/public/images/settings/top-screen/options/options-disabled.png similarity index 100% rename from app/assets/images/settings/top-screen/options/options-disabled.png rename to public/images/settings/top-screen/options/options-disabled.png diff --git a/app/assets/images/settings/top-screen/options/options.webp b/public/images/settings/top-screen/options/options.webp similarity index 100% rename from app/assets/images/settings/top-screen/options/options.webp rename to public/images/settings/top-screen/options/options.webp diff --git a/app/assets/images/settings/top-screen/options/start-up.webp b/public/images/settings/top-screen/options/start-up.webp similarity index 100% rename from app/assets/images/settings/top-screen/options/start-up.webp rename to public/images/settings/top-screen/options/start-up.webp diff --git a/app/assets/images/settings/top-screen/settings.webp b/public/images/settings/top-screen/settings.webp similarity index 100% rename from app/assets/images/settings/top-screen/settings.webp rename to public/images/settings/top-screen/settings.webp diff --git a/app/assets/images/settings/top-screen/touch_screen/touch-screen-disabled.png b/public/images/settings/top-screen/touch_screen/touch-screen-disabled.png similarity index 100% rename from app/assets/images/settings/top-screen/touch_screen/touch-screen-disabled.png rename to public/images/settings/top-screen/touch_screen/touch-screen-disabled.png diff --git a/app/assets/images/settings/top-screen/touch_screen/touch-screen.webp b/public/images/settings/top-screen/touch_screen/touch-screen.webp similarity index 100% rename from app/assets/images/settings/top-screen/touch_screen/touch-screen.webp rename to public/images/settings/top-screen/touch_screen/touch-screen.webp diff --git a/app/assets/images/settings/top-screen/user/birthday.webp b/public/images/settings/top-screen/user/birthday.webp similarity index 100% rename from app/assets/images/settings/top-screen/user/birthday.webp rename to public/images/settings/top-screen/user/birthday.webp diff --git a/app/assets/images/settings/top-screen/user/color.webp b/public/images/settings/top-screen/user/color.webp similarity index 100% rename from app/assets/images/settings/top-screen/user/color.webp rename to public/images/settings/top-screen/user/color.webp diff --git a/app/assets/images/settings/top-screen/user/message.webp b/public/images/settings/top-screen/user/message.webp similarity index 100% rename from app/assets/images/settings/top-screen/user/message.webp rename to public/images/settings/top-screen/user/message.webp diff --git a/app/assets/images/settings/top-screen/user/user-active.webp b/public/images/settings/top-screen/user/user-active.webp similarity index 100% rename from app/assets/images/settings/top-screen/user/user-active.webp rename to public/images/settings/top-screen/user/user-active.webp diff --git a/app/assets/images/settings/top-screen/user/user-disabled.png b/public/images/settings/top-screen/user/user-disabled.png similarity index 100% rename from app/assets/images/settings/top-screen/user/user-disabled.png rename to public/images/settings/top-screen/user/user-disabled.png diff --git a/app/assets/images/settings/top-screen/user/user-name.webp b/public/images/settings/top-screen/user/user-name.webp similarity index 100% rename from app/assets/images/settings/top-screen/user/user-name.webp rename to public/images/settings/top-screen/user/user-name.webp diff --git a/app/assets/images/settings/top-screen/user/user.webp b/public/images/settings/top-screen/user/user.webp similarity index 100% rename from app/assets/images/settings/top-screen/user/user.webp rename to public/images/settings/top-screen/user/user.webp