diff --git a/astro/package-lock.json b/astro/package-lock.json index 0aefba2..b19edd7 100644 --- a/astro/package-lock.json +++ b/astro/package-lock.json @@ -13,12 +13,16 @@ "@rollup/plugin-graphql": "^2.0.5", "@tailwindcss/vite": "^4.2.1", "astro": "^5.17.1", + "md5": "^2.3.0", "mdast-util-to-string": "^4.0.0", "minify-xml": "^4.5.2", "preact": "^10.28.4", "reading-time": "^1.5.0", "tailwindcss": "^4.2.1", "tslib": "^2.8.1" + }, + "devDependencies": { + "@types/md5": "^2.3.6" } }, "node_modules/@astrojs/compiler": { @@ -2728,6 +2732,13 @@ "@types/unist": "*" } }, + "node_modules/@types/md5": { + "version": "2.3.6", + "resolved": "https://registry.npmjs.org/@types/md5/-/md5-2.3.6.tgz", + "integrity": "sha512-WD69gNXtRBnpknfZcb4TRQ0XJQbUPZcai/Qdhmka3sxUR3Et8NrXoeAoknG/LghYHTf4ve795rInVYHBTQdNVA==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/mdast": { "version": "4.0.4", "resolved": "https://registry.npmjs.org/@types/mdast/-/mdast-4.0.4.tgz", @@ -3729,6 +3740,15 @@ "url": "https://github.com/sponsors/wooorm" } }, + "node_modules/charenc": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/charenc/-/charenc-0.0.2.tgz", + "integrity": "sha512-yrLQ/yVUFXkzg7EDQsPieE/53+0RlaWTs+wBrvW36cyilJ2SaDWfl4Yj7MtLTXleV9uEKefbAGUPv2/iWSooRA==", + "license": "BSD-3-Clause", + "engines": { + "node": "*" + } + }, "node_modules/chokidar": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-5.0.0.tgz", @@ -3845,6 +3865,15 @@ "uncrypto": "^0.1.3" } }, + "node_modules/crypt": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/crypt/-/crypt-0.0.2.tgz", + "integrity": "sha512-mCxBlsHFYh9C+HVpiEacem8FEBnMXgU9gy4zmNC+SXAZNB/1idgp/aulFJ4FgCi7GPEVbfyng092GqL2k2rmow==", + "license": "BSD-3-Clause", + "engines": { + "node": "*" + } + }, "node_modules/css-select": { "version": "5.2.2", "resolved": "https://registry.npmjs.org/css-select/-/css-select-5.2.2.tgz", @@ -4626,6 +4655,12 @@ "url": "https://github.com/sponsors/brc-dd" } }, + "node_modules/is-buffer": { + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz", + "integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==", + "license": "MIT" + }, "node_modules/is-docker": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/is-docker/-/is-docker-3.0.0.tgz", @@ -5065,6 +5100,17 @@ "url": "https://github.com/sponsors/wooorm" } }, + "node_modules/md5": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/md5/-/md5-2.3.0.tgz", + "integrity": "sha512-T1GITYmFaKuO91vxyoQMFETst+O71VUPEU3ze5GNzDm0OWdP8v1ziTaAEPUr/3kLsY3Sftgz242A1SetQiDL7g==", + "license": "BSD-3-Clause", + "dependencies": { + "charenc": "0.0.2", + "crypt": "0.0.2", + "is-buffer": "~1.1.6" + } + }, "node_modules/mdast-util-definitions": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/mdast-util-definitions/-/mdast-util-definitions-6.0.0.tgz", diff --git a/astro/package.json b/astro/package.json index c12bdf9..0bbe7d4 100644 --- a/astro/package.json +++ b/astro/package.json @@ -14,11 +14,15 @@ "@rollup/plugin-graphql": "^2.0.5", "@tailwindcss/vite": "^4.2.1", "astro": "^5.17.1", + "md5": "^2.3.0", "mdast-util-to-string": "^4.0.0", "minify-xml": "^4.5.2", "preact": "^10.28.4", "reading-time": "^1.5.0", "tailwindcss": "^4.2.1", "tslib": "^2.8.1" + }, + "devDependencies": { + "@types/md5": "^2.3.6" } } diff --git a/astro/src/content/photos/albums.ts b/astro/src/content/photos/albums.ts index 4e05e67..6794408 100644 --- a/astro/src/content/photos/albums.ts +++ b/astro/src/content/photos/albums.ts @@ -47,10 +47,11 @@ export async function getAllAlbums(settings: GlobalSettings): Promise { album.photos.push({ + id: photoRecord["id"], photo: { - url: photoRecord["photo"]["filename_download"], - height: photoRecord["photo"]["filename_download"]["height"], - width: photoRecord["photo"]["filename_download"]["width"] + url: photoRecord["photo"]["filename_disk"], + width: photoRecord["photo"]["width"], + height: photoRecord["photo"]["height"] }, text: photoRecord["text"] }); diff --git a/astro/src/graphql/photos/getAlbums.graphql b/astro/src/graphql/photos/getAlbums.graphql index 41cf3a1..4a711fd 100644 --- a/astro/src/graphql/photos/getAlbums.graphql +++ b/astro/src/graphql/photos/getAlbums.graphql @@ -40,7 +40,7 @@ query getAllAlbums($date: String!) { photo { id, created_on, - filename_download, + filename_disk, width, height }, diff --git a/astro/src/lib/hash.ts b/astro/src/lib/hash.ts new file mode 100644 index 0000000..de1ac67 --- /dev/null +++ b/astro/src/lib/hash.ts @@ -0,0 +1,12 @@ +import md5 from "md5"; + +export function getPhotoHash(photo: PhotoAlbumPhoto) { + const hash = md5(JSON.stringify({ + id: photo.id, + url: photo.photo.url, + width: photo.photo.width, + height: photo.photo.height + })); + + return hash.substring(hash.length - 10); +} diff --git a/astro/src/lib/routing.ts b/astro/src/lib/routing.ts index b8e273f..9d33d80 100644 --- a/astro/src/lib/routing.ts +++ b/astro/src/lib/routing.ts @@ -1,3 +1,47 @@ +import { getAllBlogs } from "@/content/blogs/blogs"; +import { getAllWebpages } from "@/content/pages/pages"; +import { getAllAlbums } from "@/content/photos/albums"; +import { getAllProjects } from "@/content/projects/projects"; +import { getPhotoHash } from "./hash"; + +export async function getAllRoutesList(settings: GlobalSettings): Promise { + let routes: string[] = []; + + const webpages = await getAllWebpages(); + + webpages.forEach((webpage) => { + routes.push(webpage.url); + }); + + if (settings.blog.enabled) { + const blogs = await getAllBlogs(settings); + + blogs.forEach((blog) => { + routes.push(getBlogRoute(settings.blog, blog)); + }); + } + if (settings.project.enabled) { + const projects = await getAllProjects(settings); + + projects.forEach((project) => { + routes.push(getProjectRoute(settings.project, project)); + }); + } + if (settings.photo.enabled) { + const galleries = await getAllAlbums(settings); + + galleries.forEach((gallery) => { + routes.push(getAlbumRoute(settings.photo, gallery)); + + gallery.photos.forEach((photo) => { + routes.push(getPhotoRoute(settings.photo, gallery, photo)); + }); + }); + } + + return routes; +} + export function getBlogRoute(blogSettings: BlogSettings, blog: BlogPost) { const date = new Date(blog.date); @@ -31,3 +75,16 @@ export function getAlbumRoute(photoSettings: WebsitePhotoSettings, album: PhotoA .replaceAll("%R", album.url) .replace(/\/+/g, '/'); } + +export function getPhotoRoute(photoSettings: WebsitePhotoSettings, album: PhotoAlbum, photo: PhotoAlbumPhoto) { + const date = new Date(album.startDate); + + return photoSettings.photo.routeTemplate + .replaceAll("%Y", date.getFullYear().toString()) + .replaceAll("%M", (date.getMonth() + 1).toString().padStart(2, '0')) + .replaceAll("%D", date.getDate().toString().padStart(2, '0')) + .replaceAll("%C", album.category.url) + .replaceAll("%R", album.url) + .replaceAll("%H", getPhotoHash(photo)) + .replace(/\/+/g, '/'); +} diff --git a/astro/src/pages/index.astro b/astro/src/pages/index.astro index 61395d5..a254ea4 100644 --- a/astro/src/pages/index.astro +++ b/astro/src/pages/index.astro @@ -1,11 +1,12 @@ --- import { getAllWebpages } from "@/content/pages/pages"; -import { getAllAlbums } from "@/content/photos/albums"; +import { getAllRoutesList } from "@/lib/routing"; import { getSettings } from "@/content/settings/settings" import WebpageLayout from "@/layouts/WebpageLayout.astro"; const settings = await getSettings(); -const webpages = await getAllWebpages(); +const routes = await getAllRoutesList(settings); +console.log(routes); --- diff --git a/astro/src/types/photos/album.d.ts b/astro/src/types/photos/album.d.ts index a98afba..14e1f44 100644 --- a/astro/src/types/photos/album.d.ts +++ b/astro/src/types/photos/album.d.ts @@ -22,6 +22,7 @@ type PhotoAlbumCategory = { } type PhotoAlbumPhoto = { + id: string; photo: PhotoProps; text: string | null; }