Compare commits
2 Commits
aa93600c79
...
f1b0d269bf
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f1b0d269bf | ||
|
|
32c698c39a |
@@ -11,7 +11,7 @@ interface Props {
|
||||
|
||||
const category = Astro.props.category;
|
||||
const settings = await getSettings();
|
||||
const categoryAlbums = await getCategoryAlbums(settings, category.category);
|
||||
const categoryAlbums = await getCategoryAlbums(settings, category.category.url);
|
||||
|
||||
console.log(categoryAlbums);
|
||||
---
|
||||
|
||||
@@ -239,7 +239,7 @@ export async function getCategoryAlbums(settings: GlobalSettings, route: string)
|
||||
const client = await createDirectusConnection();
|
||||
const result = await client.query(print(getCategoryAlbumQuery), {
|
||||
date: formatDate(new Date(), "%Y-%M-%D"),
|
||||
categoryUrl: `/${route}`
|
||||
categoryUrl: route
|
||||
});
|
||||
|
||||
let albums: PhotoAlbum[] = [];
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { createDirectusConnection } from "@/lib/directus";
|
||||
import { print } from "graphql";
|
||||
import getCategories from '@/graphql/photos/getCategories.graphql';
|
||||
import getCategory from '@/graphql/photos/getCategory.graphql';
|
||||
|
||||
export async function getAllCategories(settings: GlobalSettings): Promise<PhotoAlbumCategory[]> {
|
||||
const client = await createDirectusConnection();
|
||||
@@ -23,3 +24,26 @@ export async function getAllCategories(settings: GlobalSettings): Promise<PhotoA
|
||||
|
||||
return categories;
|
||||
}
|
||||
|
||||
export async function getPhotoCategory(url: string): Promise<PhotoAlbumCategory> {
|
||||
const client = await createDirectusConnection();
|
||||
const result = await client.query(print(getCategory), {
|
||||
url: url
|
||||
});
|
||||
|
||||
const item = result["Photo_Categories"][0];
|
||||
|
||||
let categories: PhotoAlbumCategory = {
|
||||
id: item["id"],
|
||||
title: item["title"],
|
||||
url: item["url"],
|
||||
thumbnail: {
|
||||
url: item["thumbnail"]["filename_disk"],
|
||||
width: item["thumbnail"]["width"],
|
||||
height: item["thumbnail"]["height"]
|
||||
}
|
||||
};
|
||||
|
||||
return categories;
|
||||
}
|
||||
|
||||
|
||||
17
astro/src/graphql/photos/getCategory.graphql
Normal file
17
astro/src/graphql/photos/getCategory.graphql
Normal file
@@ -0,0 +1,17 @@
|
||||
query getAllCategories($url: String!) {
|
||||
Photo_Categories(filter: { status: { _eq: "published" }, url: { _eq: $url } }) {
|
||||
id,
|
||||
date_created,
|
||||
date_updated,
|
||||
status,
|
||||
title,
|
||||
url,
|
||||
thumbnail {
|
||||
id,
|
||||
created_on,
|
||||
filename_disk,
|
||||
width,
|
||||
height
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import { getBlog } from "@/content/blogs/blogs";
|
||||
import { getWebpage } from "@/content/pages/pages";
|
||||
import { getAlbum } from "@/content/photos/albums";
|
||||
import { getAllCategories } from "@/content/photos/categories";
|
||||
import { getAllCategories, getPhotoCategory } from "@/content/photos/categories";
|
||||
import { getPhotoFromHash } from "@/content/photos/photos";
|
||||
import { getProject } from "@/content/projects/projects";
|
||||
|
||||
@@ -117,13 +117,15 @@ export async function getPage(settings: GlobalSettings, route: string): Promise<
|
||||
params[key] = match[i + 1];
|
||||
});
|
||||
|
||||
const category = await getPhotoCategory(`/${params["C"]}`);
|
||||
|
||||
return {
|
||||
route: route,
|
||||
pageType: "PhotoCategory",
|
||||
page: {
|
||||
type: "PhotoCategory",
|
||||
exists: true,
|
||||
category: params["C"],
|
||||
category: category,
|
||||
pageNumber: params["page"] !== undefined ? Number(params["page"]) : 1
|
||||
}
|
||||
};
|
||||
|
||||
@@ -42,18 +42,8 @@ if (page === null || page.page === null || !page.page.exists) {
|
||||
|
||||
{ page.page.type === "Webpage" && page.page.exists && (
|
||||
<WebpageLayout settings={{
|
||||
searchEngine: {
|
||||
title: page.page.searchEngine.title,
|
||||
description: page.page.searchEngine.description,
|
||||
allowCrawlers: page.page.searchEngine.allowCrawlers,
|
||||
canonical: page.page.searchEngine.canonical,
|
||||
priority: page.page.searchEngine.priority,
|
||||
thumbnail: {
|
||||
url: page.page.searchEngine.thumbnail.url,
|
||||
width: 1200,
|
||||
height: 630
|
||||
}
|
||||
}}}>
|
||||
searchEngine: page.page.searchEngine
|
||||
}}>
|
||||
<Fragment slot="content">
|
||||
<Webpage webpage={page.page.components} />
|
||||
</Fragment>
|
||||
@@ -152,11 +142,7 @@ if (page === null || page.page === null || !page.page.exists) {
|
||||
allowCrawlers: true,
|
||||
canonical: null,
|
||||
priority: 65,
|
||||
thumbnail: {
|
||||
url: page.page.category.thumbnail.url,
|
||||
width: 1200,
|
||||
height: 630
|
||||
}
|
||||
thumbnail: page.page.category.thumbnail
|
||||
}}}>
|
||||
<Fragment slot="content">
|
||||
<CategoryIndex />
|
||||
@@ -167,16 +153,12 @@ if (page === null || page.page === null || !page.page.exists) {
|
||||
{ page.pageType === "PhotoCategory" && (
|
||||
<WebpageLayout settings={{
|
||||
searchEngine: {
|
||||
title: "",
|
||||
title: page.page.category.title,
|
||||
description: "",
|
||||
allowCrawlers: true,
|
||||
canonical: null,
|
||||
priority: 65,
|
||||
thumbnail: {
|
||||
url: "",
|
||||
width: 1200,
|
||||
height: 630
|
||||
}
|
||||
thumbnail: page.page.category.thumbnail
|
||||
}}}>
|
||||
<Fragment slot="content">
|
||||
<Category category={page.page} />
|
||||
|
||||
2
astro/src/types/photos/album.d.ts
vendored
2
astro/src/types/photos/album.d.ts
vendored
@@ -35,6 +35,6 @@ type PhotoCategory = {
|
||||
type: "PhotoCategory";
|
||||
exists: boolean;
|
||||
|
||||
category: string;
|
||||
category: PhotoAlbumCategory;
|
||||
pageNumber: number;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user