diff --git a/src/components/Card/TagRow.astro b/src/components/Card/TagRow.astro index e1a644e..d9f8646 100644 --- a/src/components/Card/TagRow.astro +++ b/src/components/Card/TagRow.astro @@ -6,7 +6,7 @@ const { tags } = Astro.props { (tags ?? []).map(tag => ( {tag.name} diff --git a/src/data/pocketbase.ts b/src/data/pocketbase.ts index ef6d8de..c3f6c9a 100644 --- a/src/data/pocketbase.ts +++ b/src/data/pocketbase.ts @@ -29,7 +29,7 @@ class APIClient { // IMAGE 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) return relative ? res.substring(21) : res } @@ -44,6 +44,24 @@ class APIClient { return urls } + async getTag(name: string) { + return await this.client.collection(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(Collection.RECIPES).getFullList({ + filter: `tags ~ '${tag.id}'`, + expand: 'ingredients,tags,steps,images,steps.ingredients' + }) + } + } const client = new APIClient() export default client; \ No newline at end of file diff --git a/src/pages/tags/[name].astro b/src/pages/tags/[name].astro new file mode 100644 index 0000000..84159f3 --- /dev/null +++ b/src/pages/tags/[name].astro @@ -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 +--- + + +
+ { + recipes.map(r => ( + + )) + } +
+
\ No newline at end of file diff --git a/src/pages/tags/index.astro b/src/pages/tags/index.astro new file mode 100644 index 0000000..e69de29