Tag pages working!

This commit is contained in:
June 2025-08-16 14:54:38 +12:00
parent 6145f14df0
commit 0cb1d99e75
Signed by: breadone
GPG Key ID: FDC19FE143200483
4 changed files with 38 additions and 2 deletions

View File

@ -6,7 +6,7 @@ const { tags } = Astro.props
{ {
(tags ?? []).map(tag => ( (tags ?? []).map(tag => (
<a <a
href={`/tag/${tag.id}`} href={`/tags/${tag.name}`}
class="text-white bg-white/20 px-2 mr-2 mt-2 rounded-md inline-block hover:bg-white/30" class="text-white bg-white/20 px-2 mr-2 mt-2 rounded-md inline-block hover:bg-white/30"
> >
{tag.name} {tag.name}

View File

@ -29,7 +29,7 @@ class APIClient {
// IMAGE // IMAGE
async getImageURL(imgID: string, relative: boolean = true) { async getImageURL(imgID: string, relative: boolean = true) {
const record = await this.client.collection("images").getOne(imgID) const record = await this.client.collection(Collection.IMAGES).getOne(imgID)
const res = this.client.files.getURL(record, record.image) const res = this.client.files.getURL(record, record.image)
return relative ? res.substring(21) : res return relative ? res.substring(21) : res
} }
@ -44,6 +44,24 @@ class APIClient {
return urls return urls
} }
async getTag(name: string) {
return await this.client.collection<Tag>(Collection.TAGS).getList(1, 50, { filter: `name = '${name}'` })
}
async getRecipesOfTag(tagName: string) {
// get the tag id first
const tagResult = await this.getTag(tagName)
if (tagResult.items.length === 0) {
return []
}
const tag = tagResult.items[0]
return await this.client.collection<Recipe>(Collection.RECIPES).getFullList({
filter: `tags ~ '${tag.id}'`,
expand: 'ingredients,tags,steps,images,steps.ingredients'
})
}
} }
const client = new APIClient() const client = new APIClient()
export default client; export default client;

View File

@ -0,0 +1,18 @@
---
import SiteLayout from "@/layouts/base";
import client from "@/data/pocketbase";
import OverviewCard from "@/components/Card/OverviewCard";
const { name } = Astro.params
const recipes = await client.getRecipesOfTag(name) // todo redir to 404 if not found
---
<SiteLayout>
<div class="grid md:gap-2 gap-3 grid-cols-2 md:grid-cols-2 lg:grid-cols-4 xl:grid-cols-8">
{
recipes.map(r => (
<OverviewCard recipe={r} />
))
}
</div>
</SiteLayout>

View File