Finish first part of creating the full list of routes

This commit is contained in:
itsfinniii
2026-03-15 12:04:28 +01:00
parent ff811327bb
commit 4f3cc40041
8 changed files with 128 additions and 6 deletions

View File

@@ -47,10 +47,11 @@ export async function getAllAlbums(settings: GlobalSettings): Promise<PhotoAlbum
albumRecord["photos"].forEach((photoRecord: any) => {
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"]
});

View File

@@ -40,7 +40,7 @@ query getAllAlbums($date: String!) {
photo {
id,
created_on,
filename_download,
filename_disk,
width,
height
},

12
astro/src/lib/hash.ts Normal file
View File

@@ -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);
}

View File

@@ -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<string[]> {
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, '/');
}

View File

@@ -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);
---
<WebpageLayout>

View File

@@ -22,6 +22,7 @@ type PhotoAlbumCategory = {
}
type PhotoAlbumPhoto = {
id: string;
photo: PhotoProps;
text: string | null;
}