149 lines
5.3 KiB
TypeScript
149 lines
5.3 KiB
TypeScript
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";
|
|
import { getAllCategories } from "@/content/photos/categories";
|
|
|
|
export async function getAllRoutesList(settings: GlobalSettings): Promise<string[]> {
|
|
let routes: string[] = [];
|
|
|
|
const webpages = await getAllWebpages();
|
|
|
|
webpages.forEach((webpage) => {
|
|
if (webpage.exists) {
|
|
routes.push(webpage.url);
|
|
}
|
|
});
|
|
|
|
if (settings.blog.enabled) {
|
|
const blogs = await getAllBlogs(settings);
|
|
|
|
for (let i = 0; i < Math.ceil(blogs.length / 6); i++) {
|
|
if (i !== 0) {
|
|
routes.push(`${settings.blog.indexRouteTemplate}/${i + 1}`);
|
|
}
|
|
else {
|
|
routes.push(settings.blog.indexRouteTemplate);
|
|
}
|
|
}
|
|
|
|
blogs.forEach((blog) => {
|
|
routes.push(getBlogRoute(settings.blog, blog));
|
|
});
|
|
}
|
|
if (settings.project.enabled) {
|
|
const projects = await getAllProjects(settings);
|
|
|
|
for (let i = 0; i < Math.ceil(projects.length / 4); i++) {
|
|
if (i !== 0) {
|
|
routes.push(`${settings.project.indexRouteTemplate}/${i + 1}`);
|
|
}
|
|
else {
|
|
routes.push(settings.project.indexRouteTemplate);
|
|
}
|
|
}
|
|
|
|
projects.forEach((project) => {
|
|
routes.push(getProjectRoute(settings.project, project));
|
|
});
|
|
}
|
|
if (settings.photo.enabled) {
|
|
const categories = await getAllCategories(settings);
|
|
|
|
if (categories.length > 0) {
|
|
const galleries = await getAllAlbums(settings);
|
|
|
|
routes.push(settings.photo.categoryIndex.indexRouteTemplate);
|
|
|
|
categories.forEach((category) => {
|
|
let albums = galleries.filter(g => g.category.id === category.id);
|
|
const pages = Math.ceil(albums.length / settings.photo.category.perPage);
|
|
const categoryRoute = getCategoryRoute(settings.photo, category);
|
|
|
|
for (let i = 0; i < pages; i++) {
|
|
if (i !== 0) {
|
|
routes.push(`${categoryRoute}/${i + 1}`);
|
|
}
|
|
else {
|
|
routes.push(`${categoryRoute}`);
|
|
}
|
|
}
|
|
});
|
|
|
|
galleries.forEach((gallery) => {
|
|
const pages = Math.ceil(gallery.photos.length / settings.photo.album.perPage);
|
|
const galleryRoute = getAlbumRoute(settings.photo, gallery);
|
|
|
|
for (let i = 0; i < pages; i++) {
|
|
if (i !== 0) {
|
|
routes.push(`${galleryRoute}/${i + 1}`);
|
|
}
|
|
else {
|
|
routes.push(`${galleryRoute}`);
|
|
}
|
|
}
|
|
|
|
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);
|
|
|
|
return blogSettings.blogRouteTemplate
|
|
.replaceAll("%Y", date.getFullYear().toString())
|
|
.replaceAll("%M", (date.getMonth() + 1).toString().padStart(2, '0'))
|
|
.replaceAll("%D", date.getDate().toString().padStart(2, '0'))
|
|
.replaceAll("%R", blog.url)
|
|
.replace(/\/+/g, '/');
|
|
}
|
|
|
|
export function getProjectRoute(projectSettings: ProjectSettings, project: ProjectPost) {
|
|
const date = new Date(project.date);
|
|
|
|
return projectSettings.projectRouteTemplate
|
|
.replaceAll("%Y", date.getFullYear().toString())
|
|
.replaceAll("%M", (date.getMonth() + 1).toString().padStart(2, '0'))
|
|
.replaceAll("%D", date.getDate().toString().padStart(2, '0'))
|
|
.replaceAll("%R", project.url)
|
|
.replace(/\/+/g, '/');
|
|
}
|
|
|
|
export function getCategoryRoute(photoSettings: WebsitePhotoSettings, category: PhotoAlbumCategory) {
|
|
return photoSettings.category.routeTemplate
|
|
.replaceAll("%C", category.url)
|
|
.replace(/\/+/g, '/');
|
|
}
|
|
|
|
export function getAlbumRoute(photoSettings: WebsitePhotoSettings, album: PhotoAlbum) {
|
|
const date = new Date(album.startDate);
|
|
|
|
return photoSettings.album.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)
|
|
.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, '/');
|
|
}
|