Compare commits
2 Commits
44437c766b
...
c1b89c5823
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c1b89c5823 | ||
|
|
ad73ab5672 |
78
astro/src/content/photos/albums.ts
Normal file
78
astro/src/content/photos/albums.ts
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
import { createDirectusConnection } from "@/lib/directus";
|
||||||
|
import { print } from "graphql";
|
||||||
|
import getAlbums from '@/graphql/photos/getAlbums.graphql';
|
||||||
|
import { formatDate } from "@/lib/dates";
|
||||||
|
|
||||||
|
export async function getAllAlbums(settings: GlobalSettings): Promise<PhotoAlbum[]> {
|
||||||
|
const client = await createDirectusConnection();
|
||||||
|
const result = await client.query(print(getAlbums), {
|
||||||
|
date: formatDate(new Date(), "%Y-%M-%D")
|
||||||
|
});
|
||||||
|
|
||||||
|
let albums: PhotoAlbum[] = [];
|
||||||
|
|
||||||
|
result["Photo_Albums"].forEach((albumRecord: any) => {
|
||||||
|
let dates: string[] = [
|
||||||
|
settings.website.lastModified.toISOString(),
|
||||||
|
settings.photo.lastModified.toISOString(),
|
||||||
|
albumRecord["date_created"],
|
||||||
|
albumRecord["date_updated"],
|
||||||
|
albumRecord["thumbnail"]["created_on"],
|
||||||
|
];
|
||||||
|
|
||||||
|
const album: PhotoAlbum = {
|
||||||
|
title: albumRecord["title"],
|
||||||
|
description: albumRecord["description"],
|
||||||
|
url: albumRecord["url"],
|
||||||
|
startDate: albumRecord["start_date"],
|
||||||
|
endDate: albumRecord["end_date"],
|
||||||
|
location: albumRecord["location"],
|
||||||
|
category: {
|
||||||
|
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({
|
||||||
|
photo: {
|
||||||
|
url: photoRecord["photo"]["filename_download"],
|
||||||
|
height: photoRecord["photo"]["filename_download"]["height"],
|
||||||
|
width: photoRecord["photo"]["filename_download"]["width"]
|
||||||
|
},
|
||||||
|
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]);
|
||||||
|
}
|
||||||
|
|
||||||
|
albums.push(album);
|
||||||
|
});
|
||||||
|
|
||||||
|
return albums;
|
||||||
|
}
|
||||||
51
astro/src/graphql/photos/getAlbums.graphql
Normal file
51
astro/src/graphql/photos/getAlbums.graphql
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
query getAllAlbums($date: String!) {
|
||||||
|
Photo_Albums(sort: ["-start_date", "-date_created"], filter: { status: { _eq: "published" }, start_date: { _lte: $date }, 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_download,
|
||||||
|
width,
|
||||||
|
height
|
||||||
|
},
|
||||||
|
text,
|
||||||
|
sort
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,3 +19,15 @@ export function getProjectRoute(projectSettings: ProjectSettings, project: Proje
|
|||||||
.replaceAll("%R", project.url)
|
.replaceAll("%R", project.url)
|
||||||
.replace(/\/+/g, '/');
|
.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, '/');
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
---
|
---
|
||||||
import { getAllBlogs } from "@/content/blogs/blogs";
|
import { getAllAlbums } from "@/content/photos/albums";
|
||||||
import { getSettings } from "@/content/settings/settings"
|
import { getSettings } from "@/content/settings/settings"
|
||||||
import WebpageLayout from "@/layouts/WebpageLayout.astro";
|
import WebpageLayout from "@/layouts/WebpageLayout.astro";
|
||||||
|
|
||||||
const settings = await getSettings();
|
const settings = await getSettings();
|
||||||
const blogs = await getAllBlogs(settings);
|
const albums = await getAllAlbums(settings);
|
||||||
---
|
---
|
||||||
|
|
||||||
<WebpageLayout>
|
<WebpageLayout>
|
||||||
|
|||||||
@@ -1,18 +1,35 @@
|
|||||||
|
import { getAllAlbums } from "@/content/photos/albums";
|
||||||
import { getSettings } from "@/content/settings/settings";
|
import { getSettings } from "@/content/settings/settings";
|
||||||
|
import { getAlbumRoute } from "@/lib/routing";
|
||||||
import type { APIRoute } from "astro";
|
import type { APIRoute } from "astro";
|
||||||
import minifyXML from "minify-xml";
|
import minifyXML from "minify-xml";
|
||||||
|
|
||||||
export const GET = (async ({ params }) => {
|
export const GET = (async ({ params }) => {
|
||||||
const settings = await getSettings();
|
const settings = await getSettings();
|
||||||
|
|
||||||
|
if (!settings.photo.enabled) {
|
||||||
|
return new Response(null, {
|
||||||
|
status: 204,
|
||||||
|
statusText: "Not Found"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const currentPage = params.page;
|
const currentPage = params.page;
|
||||||
|
|
||||||
let pages: SitemapPage[] = [
|
const albums = await getAllAlbums(settings);
|
||||||
{
|
const selectedAlbums = albums.slice(
|
||||||
url: "/",
|
((Number(currentPage) - 1) * settings.sitemap.perPage),
|
||||||
lastModified: new Date()
|
Number(currentPage) * settings.sitemap.perPage - 1
|
||||||
}
|
);
|
||||||
];
|
|
||||||
|
let pages: SitemapPage[] = [];
|
||||||
|
|
||||||
|
selectedAlbums.forEach((album) => {
|
||||||
|
pages.push({
|
||||||
|
url: getAlbumRoute(settings.photo, album),
|
||||||
|
lastModified: album.lastModified
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
let sitemapContent = `
|
let sitemapContent = `
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
@@ -37,8 +54,9 @@ export const GET = (async ({ params }) => {
|
|||||||
|
|
||||||
export async function getStaticPaths() {
|
export async function getStaticPaths() {
|
||||||
const settings = await getSettings();
|
const settings = await getSettings();
|
||||||
|
const albums = await getAllAlbums(settings);
|
||||||
|
|
||||||
const albumCount = 250;
|
const albumCount = albums.length;
|
||||||
const perPage = settings.sitemap.perPage;
|
const perPage = settings.sitemap.perPage;
|
||||||
const pages = Math.ceil(albumCount / perPage);
|
const pages = Math.ceil(albumCount / perPage);
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { getAllAlbums } from "@/content/photos/albums";
|
||||||
import { getSettings } from "@/content/settings/settings";
|
import { getSettings } from "@/content/settings/settings";
|
||||||
import type { APIRoute } from "astro";
|
import type { APIRoute } from "astro";
|
||||||
import minifyXML from "minify-xml";
|
import minifyXML from "minify-xml";
|
||||||
@@ -5,16 +6,43 @@ import minifyXML from "minify-xml";
|
|||||||
export const GET = (async () => {
|
export const GET = (async () => {
|
||||||
const settings = await getSettings();
|
const settings = await getSettings();
|
||||||
|
|
||||||
const albumCount = 250;
|
if (!settings.photo.enabled) {
|
||||||
|
return new Response(null, {
|
||||||
|
status: 204,
|
||||||
|
statusText: "Not Found"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const albums = await getAllAlbums(settings);
|
||||||
|
const albumCount = albums.length;
|
||||||
const perPage = settings.sitemap.perPage;
|
const perPage = settings.sitemap.perPage;
|
||||||
const pages = Math.ceil(albumCount / perPage);
|
const pages = Math.ceil(albumCount / perPage);
|
||||||
|
|
||||||
let sitemaps: SitemapIndex[] = [];
|
let sitemaps: SitemapIndex[] = [];
|
||||||
|
|
||||||
for (let i = 0; i < pages; i++) {
|
for (let i = 0; i < pages; i++) {
|
||||||
|
const selectedProjects = albums.slice(
|
||||||
|
((Number(i + 1) - 1) * settings.sitemap.perPage),
|
||||||
|
Number(i + 1) * settings.sitemap.perPage - 1
|
||||||
|
);
|
||||||
|
|
||||||
|
let dates = [
|
||||||
|
settings.sitemap.lastModified,
|
||||||
|
settings.photo.lastModified,
|
||||||
|
settings.website.lastModified
|
||||||
|
];
|
||||||
|
|
||||||
|
selectedProjects.forEach((project) => {
|
||||||
|
dates.push(project.lastModified);
|
||||||
|
});
|
||||||
|
|
||||||
|
const lastModified = dates.sort((a: Date, b: Date) => {
|
||||||
|
return b.getTime() - a.getTime();
|
||||||
|
});
|
||||||
|
|
||||||
sitemaps.push({
|
sitemaps.push({
|
||||||
url: `/sitemap/albums-${i + 1}.xml`,
|
url: `/sitemap/albums-${i + 1}.xml`,
|
||||||
lastModified: new Date()
|
lastModified: lastModified[0]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { getAllBlogs } from "@/content/blogs/blogs";
|
import { getAllBlogs } from "@/content/blogs/blogs";
|
||||||
|
import { getAllAlbums } from "@/content/photos/albums";
|
||||||
import { getAllProjects } from "@/content/projects/projects";
|
import { getAllProjects } from "@/content/projects/projects";
|
||||||
import { getSettings } from "@/content/settings/settings";
|
import { getSettings } from "@/content/settings/settings";
|
||||||
import type { APIRoute } from "astro";
|
import type { APIRoute } from "astro";
|
||||||
@@ -59,10 +60,26 @@ export const GET = (async () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
if (settings.photo.enabled) {
|
if (settings.photo.enabled) {
|
||||||
|
const photoLastModifieds = [
|
||||||
|
settings.photo.lastModified,
|
||||||
|
settings.sitemap.lastModified,
|
||||||
|
settings.website.lastModified
|
||||||
|
];
|
||||||
|
|
||||||
|
let albums = await getAllAlbums(settings);
|
||||||
|
|
||||||
|
albums.forEach((album) => {
|
||||||
|
photoLastModifieds.push(album.lastModified);
|
||||||
|
});
|
||||||
|
|
||||||
|
const lastModifiedAlbums = photoLastModifieds.sort((a: Date, b: Date) => {
|
||||||
|
return b.getTime() - a.getTime();
|
||||||
|
});
|
||||||
|
|
||||||
sitemapIndex.push({
|
sitemapIndex.push({
|
||||||
url: "/sitemap/albums.xml",
|
url: "/sitemap/albums.xml",
|
||||||
lastModified: new Date()
|
lastModified: lastModifiedAlbums[0]
|
||||||
})
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
let sitemapContent = `
|
let sitemapContent = `
|
||||||
|
|||||||
27
astro/src/types/photos/album.d.ts
vendored
Normal file
27
astro/src/types/photos/album.d.ts
vendored
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
type PhotoAlbum = {
|
||||||
|
title: string;
|
||||||
|
url: string;
|
||||||
|
description: string | null;
|
||||||
|
|
||||||
|
thumbnail: PhotoProps;
|
||||||
|
|
||||||
|
startDate: string;
|
||||||
|
endDate: string | null;
|
||||||
|
location: string | null;
|
||||||
|
|
||||||
|
category: PhotoAlbumCategory;
|
||||||
|
photos: PhotoAlbumPhoto[];
|
||||||
|
|
||||||
|
lastModified: Date;
|
||||||
|
}
|
||||||
|
|
||||||
|
type PhotoAlbumCategory = {
|
||||||
|
title: string;
|
||||||
|
url: string;
|
||||||
|
thumbnail: PhotoProps;
|
||||||
|
}
|
||||||
|
|
||||||
|
type PhotoAlbumPhoto = {
|
||||||
|
photo: PhotoProps;
|
||||||
|
text: string | null;
|
||||||
|
}
|
||||||
3
astro/src/types/photos/category.d.ts
vendored
Normal file
3
astro/src/types/photos/category.d.ts
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
type PhotoCategory = {
|
||||||
|
|
||||||
|
}
|
||||||
3
astro/src/types/photos/photo.d.ts
vendored
Normal file
3
astro/src/types/photos/photo.d.ts
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
type PhotoPhoto = {
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user