Finish first part of creating the full list of routes
This commit is contained in:
@@ -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, '/');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user