diff --git a/astro/src/content/blogs/blogs.ts b/astro/src/content/blogs/blogs.ts index 91196da..6614d15 100644 --- a/astro/src/content/blogs/blogs.ts +++ b/astro/src/content/blogs/blogs.ts @@ -1,6 +1,7 @@ import { createDirectusConnection } from "@/lib/directus"; import { print } from 'graphql'; import getBlogs from '@/graphql/blogs/getBlogs.graphql'; +import getBlogPost from '@/graphql/blogs/getBlog.graphql'; import { formatDate } from "@/lib/dates"; export async function getAllBlogs(settings: GlobalSettings): Promise { @@ -23,6 +24,8 @@ export async function getAllBlogs(settings: GlobalSettings): Promise ]; const blog: BlogPost = { + type: "BlogPost", + id: blogRecord["id"], lastModified: new Date(), title: blogRecord["title"], content: blogRecord["content"], @@ -70,3 +73,69 @@ export async function getAllBlogs(settings: GlobalSettings): Promise return blogs; } + +export async function getBlog(settings: GlobalSettings, route: string): Promise { + const client = await createDirectusConnection(); + const result = await client.query(print(getBlogPost), { + route: route + }); + + const blogRecord = result["Blogs"][0]; + + let dates: string[] = [ + settings.blog.lastModified.toISOString(), + settings.website.lastModified.toISOString(), + blogRecord["date_created"], + blogRecord["date_updated"], + blogRecord["search_engine"][0]["date_created"], + blogRecord["search_engine"][0]["date_updated"], + blogRecord["search_engine"][0]["thumbnail"]["created_on"] + ]; + + const blog: BlogPost = { + type: "BlogPost", + id: blogRecord["id"], + lastModified: new Date(), + title: blogRecord["title"], + content: blogRecord["content"], + date: blogRecord["date"], + url: blogRecord["url"], + searchEngine: { + title: blogRecord["search_engine"][0]["title"], + description: blogRecord["search_engine"][0]["description"], + allowCrawlers: blogRecord["search_engine"][0]["allow_crawler"], + canonical: blogRecord["search_engine"][0]["canonical"], + priority: blogRecord["search_engine"][0]["priority"], + thumbnail: { + url: blogRecord["search_engine"][0]["thumbnail"]["filename_disk"], + height: blogRecord["search_engine"][0]["thumbnail"]["height"], + width: blogRecord["search_engine"][0]["thumbnail"]["width"] + } + }, + tags: [] + }; + + blogRecord["tags"].forEach((tagRecord: any) => { + blog["tags"].push({ + text: tagRecord["Tags_id"]["text"], + code: tagRecord["Tags_id"]["code"], + color: tagRecord["Tags_id"]["color"] + }); + + dates.push(tagRecord["Tags_id"]["date_created"]); + dates.push(tagRecord["Tags_id"]["date_updated"]); + }); + + if (dates.filter(e => e !== null).length === 0) { + blog.lastModified = new Date(); + } + else { + const sortedDates: string[] = dates.sort((a: string, b: string) => { + return new Date(b).getTime() - new Date(a).getTime(); + }); + + blog.lastModified = new Date(sortedDates[0]); + } + + return blog; +} diff --git a/astro/src/content/pages/pages.ts b/astro/src/content/pages/pages.ts index 9d18155..f35ab48 100644 --- a/astro/src/content/pages/pages.ts +++ b/astro/src/content/pages/pages.ts @@ -2,6 +2,7 @@ import { createDirectusConnection } from "@/lib/directus"; import { print } from 'graphql'; import { formatDate } from "@/lib/dates"; import getAllPages from "@/graphql/pages/getAllPages.graphql"; +import getPage from "@/graphql/pages/getPage.graphql"; export function dataToPage(pageRecord: any): WebPage { let dates: string[] = [ @@ -285,6 +286,7 @@ export function dataToPage(pageRecord: any): WebPage { } let page: WebPage = { + type: "Webpage", id: pageRecord["id"], lastModified: lastModified, url: pageRecord["url"], @@ -320,3 +322,13 @@ export async function getAllWebpages(): Promise { return pages; } + +export async function getWebpage(route: string): Promise { + const client = await createDirectusConnection(); + const result = await client.query(print(getPage), { + date: formatDate(new Date(), "%Y-%M-%D"), + route: route + }); + + return dataToPage(result["Pages"][0]); +} diff --git a/astro/src/content/photos/albums.ts b/astro/src/content/photos/albums.ts index 2137357..bd4296c 100644 --- a/astro/src/content/photos/albums.ts +++ b/astro/src/content/photos/albums.ts @@ -1,6 +1,7 @@ import { createDirectusConnection } from "@/lib/directus"; import { print } from "graphql"; import getAlbums from '@/graphql/photos/getAlbums.graphql'; +import getAlbumItem from '@/graphql/photos/getAlbum.graphql'; import { formatDate } from "@/lib/dates"; export async function getAllAlbums(settings: GlobalSettings): Promise { @@ -21,6 +22,7 @@ export async function getAllAlbums(settings: GlobalSettings): Promise { + const client = await createDirectusConnection(); + const result = await client.query(print(getAlbumItem), { + route: route + }); + + const albumRecord = result["Photo_Albums"][0]; + + let dates: string[] = [ + settings.website.lastModified.toISOString(), + settings.photo.lastModified.toISOString(), + albumRecord["date_created"], + albumRecord["date_updated"], + albumRecord["thumbnail"]["created_on"], + ]; + + const album: PhotoAlbum = { + type: "PhotoAlbum", + title: albumRecord["title"], + description: albumRecord["description"], + url: albumRecord["url"], + startDate: albumRecord["start_date"], + endDate: albumRecord["end_date"], + location: albumRecord["location"], + category: { + id: albumRecord["category"][0]["Photo_Categories_id"]["id"], + title: albumRecord["category"][0]["Photo_Categories_id"]["title"], + url: albumRecord["category"][0]["Photo_Categories_id"]["url"], + thumbnail: { + url: albumRecord["category"][0]["Photo_Categories_id"]["thumbnail"]["filename_disk"], + height: albumRecord["category"][0]["Photo_Categories_id"]["thumbnail"]["height"], + width: albumRecord["category"][0]["Photo_Categories_id"]["thumbnail"]["width"] + } + }, + thumbnail: { + url: albumRecord["thumbnail"]["filename_download"], + height: albumRecord["thumbnail"]["height"], + width: albumRecord["thumbnail"]["width"] + }, + photos: [], + lastModified: new Date() + }; + + albumRecord["photos"].forEach((photoRecord: any) => { + album.photos.push({ + id: photoRecord["id"], + photo: { + url: photoRecord["photo"]["filename_disk"], + width: photoRecord["photo"]["width"], + height: photoRecord["photo"]["height"] + }, + text: photoRecord["text"] + }); + + dates.push(photoRecord["date_created"]); + dates.push(photoRecord["date_updated"]); + dates.push(photoRecord["photo"]["created_on"]); + }); + + if (dates.filter(e => e !== null).length === 0) { + album.lastModified = new Date(); + } + else { + const sortedDates: string[] = dates.sort((a: string, b: string) => { + return new Date(b).getTime() - new Date(a).getTime(); + }); + + album.lastModified = new Date(sortedDates[0]); + } + + return album; +} diff --git a/astro/src/content/photos/categories.ts b/astro/src/content/photos/categories.ts index 5e8be64..83cfd15 100644 --- a/astro/src/content/photos/categories.ts +++ b/astro/src/content/photos/categories.ts @@ -22,4 +22,4 @@ export async function getAllCategories(settings: GlobalSettings): Promise { + const client = await createDirectusConnection(); + const result = await client.query(print(getPhotos)); + + result["Photo_Albums"][0]["photos"].forEach((photo: any) => { + const hashObject = md5(JSON.stringify({ + id: photo.id, + url: photo.photo.url, + width: photo.photo.width, + height: photo.photo.height + })); + + if (hash.substring(hash.length - 10) === hash) { + return { + id: photo.id, + text: photo.text, + photo: { + url: photo.photo.url, + width: photo.photo.width, + height: photo.photo.height + } + } + } + }); +} diff --git a/astro/src/content/projects/projects.ts b/astro/src/content/projects/projects.ts index 053d884..724c106 100644 --- a/astro/src/content/projects/projects.ts +++ b/astro/src/content/projects/projects.ts @@ -2,7 +2,7 @@ import { formatDate } from "@/lib/dates"; import { createDirectusConnection } from "@/lib/directus"; import { print } from "graphql"; import getProjects from '@/graphql/projects/getProjects.graphql'; - +import getProjectPost from '@/graphql/projects/getProject.graphql'; export async function getAllProjects(settings: GlobalSettings): Promise { const client = await createDirectusConnection(); @@ -71,3 +71,67 @@ export async function getAllProjects(settings: GlobalSettings): Promise { + const client = await createDirectusConnection(); + const result = await client.query(print(getProjectPost), { + route: route + }); + + const projectRecord = result["Projects"][0]; + + let dates: string[] = [ + settings.project.lastModified.toISOString(), + settings.website.lastModified.toISOString(), + projectRecord["date_created"], + projectRecord["date_updated"], + projectRecord["search_engine"][0]["date_created"], + projectRecord["search_engine"][0]["date_updated"], + projectRecord["search_engine"][0]["thumbnail"]["created_on"] + ]; + + const project: ProjectPost = { + lastModified: new Date(), + title: projectRecord["title"], + content: projectRecord["content"], + date: projectRecord["date"], + url: projectRecord["url"], + searchEngine: { + title: projectRecord["search_engine"][0]["title"], + description: projectRecord["search_engine"][0]["description"], + allowCrawlers: projectRecord["search_engine"][0]["allow_crawler"], + canonical: projectRecord["search_engine"][0]["canonical"], + priority: projectRecord["search_engine"][0]["priority"], + thumbnail: { + url: projectRecord["search_engine"][0]["thumbnail"]["filename_disk"], + height: projectRecord["search_engine"][0]["thumbnail"]["height"], + width: projectRecord["search_engine"][0]["thumbnail"]["width"] + } + }, + tags: [] + }; + + projectRecord["tags"].forEach((tagRecord: any) => { + project["tags"].push({ + text: tagRecord["Tags_id"]["text"], + code: tagRecord["Tags_id"]["code"], + color: tagRecord["Tags_id"]["color"] + }); + + dates.push(tagRecord["Tags_id"]["date_created"]); + dates.push(tagRecord["Tags_id"]["date_updated"]); + }); + + if (dates.filter(e => e !== null).length === 0) { + project.lastModified = new Date(); + } + else { + const sortedDates: string[] = dates.sort((a: string, b: string) => { + return new Date(b).getTime() - new Date(a).getTime(); + }); + + project.lastModified = new Date(sortedDates[0]); + } + + return project; +} diff --git a/astro/src/graphql/blogs/getBlog.graphql b/astro/src/graphql/blogs/getBlog.graphql new file mode 100644 index 0000000..c31c5da --- /dev/null +++ b/astro/src/graphql/blogs/getBlog.graphql @@ -0,0 +1,39 @@ +query getAllBlogs($route: String!) { + Blogs(sort: ["-date", "-date_created"], filter: { status: { _eq: "published" }, url: { _eq: $route } }) { + id, + date_created, + date_updated, + status, + title, + url, + date, + content, + tags { + Tags_id { + id, + date_created, + date_updated, + text, + code, + color + } + }, + search_engine { + id, + date_created, + date_updated, + title, + description, + thumbnail { + id, + created_on, + filename_disk, + width, + height + }, + canonical, + allow_crawler, + priority + } + } +} diff --git a/astro/src/graphql/blogs/getBlogs.graphql b/astro/src/graphql/blogs/getBlogs.graphql index 23863ac..cf8427a 100644 --- a/astro/src/graphql/blogs/getBlogs.graphql +++ b/astro/src/graphql/blogs/getBlogs.graphql @@ -1,5 +1,5 @@ query getAllBlogs($date: String!) { - Blogs(sort: ["-date", "-date_created"], filter: { status: { _eq: "published" }, date: { _gte: $date } }) { + Blogs(sort: ["-date", "-date_created"], filter: { status: { _eq: "published" }, date: { _lte: $date } }) { id, date_created, date_updated, diff --git a/astro/src/graphql/pages/getPage.graphql b/astro/src/graphql/pages/getPage.graphql new file mode 100644 index 0000000..14bf48d --- /dev/null +++ b/astro/src/graphql/pages/getPage.graphql @@ -0,0 +1,216 @@ +query getAllPages($date: String!, $route: String!) { + Pages(filter: { status: { _eq: "published" }, url: { _eq: $route } }) { + id, + date_created, + date_updated, + status, + url, + search_engine { + id, + date_created, + date_updated, + title, + description, + thumbnail { + id, + created_on, + filename_disk, + width, + height + }, + canonical, + allow_crawler, + priority + }, + components { + id, + __typename, + item { + __typename, + + ...on Hero { + hero_id: id, + hero_created: date_created, + hero_updated: date_updated, + hero_title: title, + hero_text: subtext, + background_image { + id, + created_on, + filename_disk, + width, + height + } + hero_image: background_image { + id, + created_on, + filename_disk, + width, + height + } + background_image { + id, + created_on, + filename_disk, + width, + height + } + } + + ...on Text_With_Side_Image { + twsi_id: id, + twsi_created: date_created, + twsi_updated: date_updated, + twsi_title: title, + twsi_text: text, + image { + id, + created_on, + filename_disk, + width, + height + }, + twsi_image_side: image_side + } + + ...on Wall_Of_Text { + wot_id: id, + wot_created: date_created, + wot_updated: date_updated, + wot_title: title, + wot_text: text + } + + ...on Frequently_Asked_Questions { + faq_id: id, + faq_created: date_created, + faq_updated: date_updated, + faq_title: title, + faq_text: text, + questions { + id, + date_created, + date_updated, + question, + answer + } + } + + ...on Upcoming_Events { + ue_id: id, + ue_created: date_created, + ue_updated: date_updated, + ue_title: title, + ue_text: text, + events(filter: { start_date: { _gte: $date } }) { + id, + date_created, + date_updated, + title, + description, + location, + map_location, + start_date, + end_date + } + } + + ...on Equipment_Table { + et_id: id, + et_created: date_created, + et_updated: date_updated, + et_title: title, + et_text: text, + items { + id, + date_created, + date_updated, + title, + text, + icon { + id, + created_on, + filename_disk, + width, + height + } + } + } + + ...on Review_List { + rl_id: id, + rl_created: date_created, + rl_updated: date_updated, + rl_title: title, + rl_text: text, + reviews(sort: ["date"], filter: { status: { _eq: "published" } }) { + id, + date_created, + date_updated, + name, + review, + date, + stars, + thumbnail { + id, + created_on, + filename_disk, + width, + height + } + } + } + + ...on Contact { + c_id: id, + c_created: date_created, + c_updated: date_updated, + c_title: title, + c_text: text, + methods { + id, + date_created, + date_updated, + title, + text, + icon { + id, + created_on, + filename_disk, + width, + height + }, + color + } + } + + ...on Last_Blogs { + lb_id: id, + lb_created: date_created, + lb_updated: date_updated, + lb_title: title, + lb_read_more_button_text: read_more_button_text, + lb_amount: amount + } + + ...on Last_Projects { + lp_id: id, + lp_created: date_created, + lp_updated: date_updated, + lp_title: title, + lp_read_more_button_text: read_more_button_text, + lp_amount: amount + } + + ...on Last_Galleries { + lg_id: id, + lg_created: date_created, + lg_updated: date_updated, + lg_title: title, + lg_read_more_button_text: read_more_button_text, + lg_amount: amount + } + } + } + } +} \ No newline at end of file diff --git a/astro/src/graphql/photos/getAlbum.graphql b/astro/src/graphql/photos/getAlbum.graphql new file mode 100644 index 0000000..3fd2a53 --- /dev/null +++ b/astro/src/graphql/photos/getAlbum.graphql @@ -0,0 +1,51 @@ +query getAllAlbums($route: String!) { + Photo_Albums(sort: ["-start_date", "-date_created"], filter: { status: { _eq: "published" }, url: { _eq: $route }, category: { Photo_Categories_id: { status: { _eq: "published" } } } }) { + id, + date_created, + date_updated, + title, + description, + url, + thumbnail { + id, + created_on, + filename_download, + width, + height + }, + start_date, + end_date, + location, + category { + Photo_Categories_id { + id, + status, + date_created, + date_updated, + title, + url, + thumbnail { + id, + created_on, + filename_download, + width, + height + } + } + }, + photos(filter: { status: { _eq: "published" } }) { + id, + date_created, + date_updated, + photo { + id, + created_on, + filename_disk, + width, + height + }, + text, + sort + } + } +} diff --git a/astro/src/graphql/photos/getPhotos.graphql b/astro/src/graphql/photos/getPhotos.graphql new file mode 100644 index 0000000..85d79a0 --- /dev/null +++ b/astro/src/graphql/photos/getPhotos.graphql @@ -0,0 +1,51 @@ +query getPhotos { + Photo_Albums(sort: ["-start_date", "-date_created"], filter: { status: { _eq: "published" }, url: { _eq: "/mirai-nexus-2026" }, category: { Photo_Categories_id: { status: { _eq: "published" } } } }) { + id, + date_created, + date_updated, + title, + description, + url, + thumbnail { + id, + created_on, + filename_download, + width, + height + }, + start_date, + end_date, + location, + category { + Photo_Categories_id { + id, + status, + date_created, + date_updated, + title, + url, + thumbnail { + id, + created_on, + filename_download, + width, + height + } + } + }, + photos(filter: { status: { _eq: "published" } }) { + id, + date_created, + date_updated, + photo { + id, + created_on, + filename_disk, + width, + height + }, + text, + sort + } + } +} diff --git a/astro/src/graphql/projects/getProject.graphql b/astro/src/graphql/projects/getProject.graphql new file mode 100644 index 0000000..7bb4f6d --- /dev/null +++ b/astro/src/graphql/projects/getProject.graphql @@ -0,0 +1,39 @@ +query getAllProjects($route: String!) { + Projects(sort: ["-date", "-date_created"], filter: { status: { _eq: "published" }, url: { _eq: $route } }) { + id, + date_created, + date_updated, + status, + title, + url, + date, + content, + tags { + Tags_id { + id, + date_created, + date_updated, + text, + code, + color + } + }, + search_engine { + id, + date_created, + date_updated, + title, + description, + thumbnail { + id, + created_on, + filename_download, + width, + height + }, + canonical, + allow_crawler, + priority + } + } +} diff --git a/astro/src/graphql/projects/getProjects.graphql b/astro/src/graphql/projects/getProjects.graphql index 9a05ad1..9adfbe0 100644 --- a/astro/src/graphql/projects/getProjects.graphql +++ b/astro/src/graphql/projects/getProjects.graphql @@ -1,5 +1,5 @@ query getAllProjects($date: String!) { - Projects(sort: ["-date", "-date_created"], filter: { status: { _eq: "published" }, date: { _gte: $date } }) { + Projects(sort: ["-date", "-date_created"], filter: { status: { _eq: "published" }, date: { _lte: $date } }) { id, date_created, date_updated, diff --git a/astro/src/lib/pages.ts b/astro/src/lib/pages.ts new file mode 100644 index 0000000..a6ff368 --- /dev/null +++ b/astro/src/lib/pages.ts @@ -0,0 +1,203 @@ +import { getBlog } from "@/content/blogs/blogs"; +import { getWebpage } from "@/content/pages/pages"; +import { getAlbum } from "@/content/photos/albums"; +import { getPhotoFromHash } from "@/content/photos/photos"; +import { getProject } from "@/content/projects/projects"; + +export async function getPage(settings: GlobalSettings, route: string): Promise { + // Blog Index + if (regexToRoute({ template: settings.blog.indexRouteTemplate, allowPagination: true }).regex.test(route)) { + const { regex, keys } = regexToRoute({ template: settings.blog.indexRouteTemplate, allowPagination: true }); + const match = route.match(regex); + const params: Record = {}; + + if (!match) return null; + + keys.forEach((key, i) => { + params[key] = match[i + 1]; + }); + + return { + route: route, + pageType: "BlogIndex", + page: { + type: "BlogIndex", + pageNumber: params["page"] !== undefined ? Number(params["page"]) : 1 + } + }; + } + // Blog Post + else if (regexToRoute({ template: settings.blog.blogRouteTemplate, allowPagination: false }).regex.test(route)) { + const { regex, keys } = regexToRoute({ template: settings.blog.blogRouteTemplate, allowPagination: false }); + const match = route.match(regex); + const params: Record = {}; + + if (!match) return null; + + keys.forEach((key, i) => { + params[key] = match[i + 1]; + }); + + const blog = await getBlog(settings, `/${params["R"]}`); + + return { + route: route, + pageType: "BlogPost", + page: blog + }; + } + // Project Index + else if (regexToRoute({ template: settings.project.indexRouteTemplate, allowPagination: true }).regex.test(route)) { + const { regex, keys } = regexToRoute({ template: settings.project.indexRouteTemplate, allowPagination: true }); + const match = route.match(regex); + const params: Record = {}; + + if (!match) return null; + + keys.forEach((key, i) => { + params[key] = match[i + 1]; + }); + + return { + route: route, + pageType: "ProjectIndex", + page: null + }; + } + // Project Post + else if (regexToRoute({ template: settings.project.projectRouteTemplate, allowPagination: false }).regex.test(route)) { + const { regex, keys } = regexToRoute({ template: settings.project.projectRouteTemplate, allowPagination: false }); + const match = route.match(regex); + const params: Record = {}; + + if (!match) return null; + + keys.forEach((key, i) => { + params[key] = match[i + 1]; + }); + + const project = await getProject(settings, `/${params["R"]}`); + + return { + route: route, + pageType: "ProjectPost", + page: project + }; + } + // Photo Category Index + else if (regexToRoute({ template: settings.photo.categoryIndex.indexRouteTemplate, allowPagination: false }).regex.test(route)) { + return { + route: route, + pageType: "PhotoCategoryIndex", + page: { + type: "PhotoCategoryIndex" + } + }; + } + // Photo Category / Album List + else if (regexToRoute({ template: settings.photo.category.routeTemplate, allowPagination: true }).regex.test(route)) { + const { regex, keys } = regexToRoute({ template: settings.photo.category.routeTemplate, allowPagination: true }); + const match = route.match(regex); + const params: Record = {}; + + if (!match) return null; + + keys.forEach((key, i) => { + params[key] = match[i + 1]; + }); + + return { + route: route, + pageType: "PhotoCategory", + page: { + type: "PhotoCategory", + category: params["category"], + pageNumber: params["page"] !== undefined ? Number(params["page"]) : 1 + } + }; + } + // Photo Album + else if (regexToRoute({ template: settings.photo.album.routeTemplate, allowPagination: true }).regex.test(route)) { + const { regex, keys } = regexToRoute({ template: settings.photo.album.routeTemplate, allowPagination: true }); + const match = route.match(regex); + const params: Record = {}; + + if (!match) return null; + + keys.forEach((key, i) => { + params[key] = match[i + 1]; + }); + + const photoAlbum = await getAlbum(settings, `/${params["R"]}`); + + return { + route: route, + pageType: "PhotoAlbum", + page: photoAlbum + }; + } + // Photograph + else if (regexToRoute({ template: settings.photo.photo.routeTemplate, allowPagination: false }).regex.test(route)) { + const { regex, keys } = regexToRoute({ template: settings.photo.photo.routeTemplate, allowPagination: false }); + const match = route.match(regex); + const params: Record = {}; + + if (!match) return null; + + keys.forEach((key, i) => { + params[key] = match[i + 1]; + }); + + console.log(params); + const photo = await getPhotoFromHash(`/${params["R"]}`, params["H"]); + + if (photo === null) {} + + return { + route: route, + pageType: "Photo", + page: { + type: "PhotoPage", + id: photo!.id, + photo: photo!.photo, + text: photo!.text + } + }; + } + else if (regexToRoute({ template: "/", allowPagination: false }).regex.test(route) || + regexToRoute({ template: "/%R", allowPagination: false }).regex.test(route)) { + const webpageContent = await getWebpage(route); + + return { + route: route, + pageType: "Webpage", + page: webpageContent + }; + } + else { + return null; + } +} + +function regexToRoute(template: PageRegexMatchProps) { + const keys: string[] = []; + + let pattern = template.template + .replaceAll("%Y", () => { keys.push("Y"); return "(\\d{4})"; }) + .replaceAll("%M", () => { keys.push("M"); return "(\\d{2})"; }) + .replaceAll("%D", () => { keys.push("D"); return "(\\d{2})"; }) + .replaceAll("%R", () => { keys.push("R"); return "([^/]+)"; }) + .replaceAll("%C", () => { keys.push("C"); return "([^/]+)"; }) + .replaceAll("%H", () => { keys.push("H"); return "([^/]+)"; }) + .replace(/\/+/g, "/"); + + if (template.allowPagination) { + keys.push("page"); + pattern += "(?:\\/(\\d+))?"; + } + + return { + regex: new RegExp(`^${pattern}$`), + keys + }; +} diff --git a/astro/src/lib/routing.ts b/astro/src/lib/routing.ts index 9cfd101..d350504 100644 --- a/astro/src/lib/routing.ts +++ b/astro/src/lib/routing.ts @@ -17,6 +17,15 @@ export async function getAllRoutesList(settings: GlobalSettings): Promise { routes.push(getBlogRoute(settings.blog, blog)); }); @@ -24,6 +33,15 @@ export async function getAllRoutesList(settings: GlobalSettings): Promise { routes.push(getProjectRoute(settings.project, project)); }); @@ -32,6 +50,8 @@ export async function getAllRoutesList(settings: GlobalSettings): Promise { let albums = galleries.filter(g => g.category.id === category.id); const pages = Math.ceil(albums.length / settings.photo.category.perPage); diff --git a/astro/src/pages/index.astro b/astro/src/pages/index.astro index a254ea4..67572b5 100644 --- a/astro/src/pages/index.astro +++ b/astro/src/pages/index.astro @@ -1,12 +1,14 @@ --- -import { getAllWebpages } from "@/content/pages/pages"; import { getAllRoutesList } from "@/lib/routing"; +import { getPage } from "@/lib/pages"; import { getSettings } from "@/content/settings/settings" import WebpageLayout from "@/layouts/WebpageLayout.astro"; const settings = await getSettings(); const routes = await getAllRoutesList(settings); console.log(routes); +const page = await getPage(settings, "/album/2026/mirai-nexus-2026/6c0e4453ab"); +console.log(page); --- diff --git a/astro/src/types/blogs/blog.d.ts b/astro/src/types/blogs/blog.d.ts index b0ebb2b..4a52275 100644 --- a/astro/src/types/blogs/blog.d.ts +++ b/astro/src/types/blogs/blog.d.ts @@ -1,4 +1,7 @@ type BlogPost = { + type: "BlogPost"; + + id: string; title: string; url: string; date: string; @@ -10,3 +13,8 @@ type BlogPost = { lastModified: Date; } + +type BlogIndex = { + type: "BlogIndex"; + pageNumber: number; +} diff --git a/astro/src/types/pages/page.d.ts b/astro/src/types/pages/page.d.ts index 5a70e27..0b93884 100644 --- a/astro/src/types/pages/page.d.ts +++ b/astro/src/types/pages/page.d.ts @@ -1,4 +1,6 @@ type WebPage = { + type: "Webpage"; + id: string; lastModified: Date; @@ -19,3 +21,20 @@ type WebpageComponent = ReviewListComponent | TextWithImageComponent | WallOfTextComponent; + + +type PageRegexMatchProps = { + template: string; + allowPagination: boolean; +} + +type PageType = { + route: string; + pageType: "Webpage" | "BlogIndex" | "BlogPost" | + "ProjectIndex" | "ProjectPost" | "PhotoCategoryIndex" | + "PhotoCategory" | "PhotoAlbum" | "Photo"; + page: WebPage | BlogPost | ProjectPost | BlogIndex | + ProjectIndex | PhotoCategoryIndex | PhotoCategory | + PhotoAlbum | PhotoPage | null; +} + diff --git a/astro/src/types/photos/album.d.ts b/astro/src/types/photos/album.d.ts index d432c5b..f3c2dd6 100644 --- a/astro/src/types/photos/album.d.ts +++ b/astro/src/types/photos/album.d.ts @@ -1,4 +1,6 @@ type PhotoAlbum = { + type: "PhotoAlbum"; + title: string; url: string; description: string | null; @@ -27,3 +29,9 @@ type PhotoAlbumPhoto = { photo: PhotoProps; text: string | null; } + +type PhotoCategory = { + type: "PhotoCategory"; + category: string; + pageNumber: number; +} diff --git a/astro/src/types/photos/category.d.ts b/astro/src/types/photos/category.d.ts index d449e9a..c291c04 100644 --- a/astro/src/types/photos/category.d.ts +++ b/astro/src/types/photos/category.d.ts @@ -1,3 +1,3 @@ -type PhotoCategory = { - +type PhotoCategoryIndex = { + type: "PhotoCategoryIndex"; } diff --git a/astro/src/types/photos/photo.d.ts b/astro/src/types/photos/photo.d.ts index 9c24dc5..08df0d6 100644 --- a/astro/src/types/photos/photo.d.ts +++ b/astro/src/types/photos/photo.d.ts @@ -1,3 +1,6 @@ -type PhotoPhoto = { - +type PhotoPage = { + type: "PhotoPage"; + id: string; + photo: PhotoProps; + text: string | null; } diff --git a/astro/src/types/projects/project.d.ts b/astro/src/types/projects/project.d.ts index 661accf..04a1a46 100644 --- a/astro/src/types/projects/project.d.ts +++ b/astro/src/types/projects/project.d.ts @@ -10,3 +10,8 @@ type ProjectPost = { lastModified: Date; } + +type ProjectIndex = { + type: "ProjectIndex"; + pageNumber: number; +}