From 241a71aeab1e5c9b7f3a0161a70bb36a45780e81 Mon Sep 17 00:00:00 2001 From: Andrea Diotallevi Date: Sat, 28 Sep 2024 14:55:41 +0100 Subject: [PATCH] feat: use SSR for shop pages --- astro/src/pages/shop/[category]/[slug].astro | 37 +-- astro/src/pages/shop/[category]/_ssg.astro | 241 +++++++++++++++++++ astro/src/pages/shop/_index-ssg.astro | 64 +++++ astro/src/pages/shop/index.astro | 20 +- 4 files changed, 340 insertions(+), 22 deletions(-) create mode 100644 astro/src/pages/shop/[category]/_ssg.astro create mode 100644 astro/src/pages/shop/_index-ssg.astro diff --git a/astro/src/pages/shop/[category]/[slug].astro b/astro/src/pages/shop/[category]/[slug].astro index 2349165..c34e792 100644 --- a/astro/src/pages/shop/[category]/[slug].astro +++ b/astro/src/pages/shop/[category]/[slug].astro @@ -1,24 +1,21 @@ --- +export const prerender = false + import { Image } from "@unpic/astro" import BaseLayout from "@layouts/BaseLayout.astro" import Button from "@components/Button.astro" -import LocalisedPrice from "@components/LocalisedPrice.astro" -import { getActivePrices, type StripePrice } from "@utils/stripe" +import { getLocalCurrency } from "@utils/currency" +import { formatCurrency } from "@utils/intl" +import { getStripePrices } from "@utils/serverless" +import { type StripePrice } from "@utils/stripe" -export async function getStaticPaths() { - const prices = await getActivePrices() +const { slug } = Astro.params +const prices = await getStripePrices() - return prices.map(price => ({ - params: { - slug: price.product.metadata.slug, - category: price.product.metadata.category, - }, - props: { price }, - })) -} +const price = prices.filter(price => price.product.metadata.slug === slug)[0] -const { price } = Astro.props +if (!price) return Astro.redirect("/404") const sizeToDescription: Record< StripePrice["product"]["metadata"]["size"], @@ -28,6 +25,10 @@ const sizeToDescription: Record< A2: "A2 (420 x 594 mm)", A1: "A1 (594 x 841 mm)", } + +const currency = getLocalCurrency( + Astro.locals.netlify.context.geo.country?.name +) ---

- + { + formatCurrency({ + value: price.currency_options[currency] + .unit_amount, + currency, + }) + }

Apply promotion codes at checkout.

diff --git a/astro/src/pages/shop/[category]/_ssg.astro b/astro/src/pages/shop/[category]/_ssg.astro new file mode 100644 index 0000000..2349165 --- /dev/null +++ b/astro/src/pages/shop/[category]/_ssg.astro @@ -0,0 +1,241 @@ +--- +import { Image } from "@unpic/astro" +import BaseLayout from "@layouts/BaseLayout.astro" +import Button from "@components/Button.astro" +import LocalisedPrice from "@components/LocalisedPrice.astro" + +import { getActivePrices, type StripePrice } from "@utils/stripe" + +export async function getStaticPaths() { + const prices = await getActivePrices() + + return prices.map(price => ({ + params: { + slug: price.product.metadata.slug, + category: price.product.metadata.category, + }, + props: { price }, + })) +} + +const { price } = Astro.props + +const sizeToDescription: Record< + StripePrice["product"]["metadata"]["size"], + string +> = { + A3: "A3 (297 x 420 mm)", + A2: "A2 (420 x 594 mm)", + A1: "A1 (594 x 841 mm)", +} +--- + + +
+
+
+ { + price.product.images.map((src, index) => ( + {price.product.name} + )) + } +
+
+ { + price.product.images.map((img, index) => ( + {`Thumbnail + )) + } +
+
+ +
+

+ {price.product.metadata.displayName} +

+ +
+
+

Size

+ +

The image is printed full bleed with no border.

+
+
+

+ 100% cotton paper +

+

+ The artwork is printed on a white cotton paper called + Hahnemühle photo rag 308gsm. With its characteristic, + wonderfully soft feel, it boasts a lightly defined felt + structure, lending each artwork a three-dimensional + appearance and impressive pictorial depth. +

+
+
+

+ Premium print quality +

+

+ The print is crafted using premium, pigment-based inks + that are fade-resistant and can endure for up to 200 + years. This technique, called Giclée, makes the print + stand apart with its extremely high level of quality, + longevity and value compared to a standard print. +

+
+
+

Free shipping

+

+ Shipping is handled by The Print Space in London through + First Class Tracked Mail (typically 6-10 days). This is + an extremely more secure option than regular post for + sending art prints. +

+
+
+

+ No custom charges for UK, EU and US orders +

+

+ With production in the UK, USA & Germany, The Print + Space guarantees no extra customs charges on UK-EU-US + orders. +

+
+
+

+ +

+

Apply promotion codes at checkout.

+
+
+
+
+
+ + + + diff --git a/astro/src/pages/shop/_index-ssg.astro b/astro/src/pages/shop/_index-ssg.astro new file mode 100644 index 0000000..5fabb29 --- /dev/null +++ b/astro/src/pages/shop/_index-ssg.astro @@ -0,0 +1,64 @@ +--- +import { Image } from "@unpic/astro" +import BaseLayout from "@layouts/BaseLayout.astro" +import LocalisedPrice from "@components/LocalisedPrice.astro" + +import { getActivePrices } from "@utils/stripe" + +const prices = await getActivePrices() +--- + + +
+
+

Shop

+

+ Archival quality giclée generative art prints, on vegan + certified Hahnemühle photo rag 308gsm matte paper, delivered in + recycled packaging +

+
+ +
+ { + prices.map(price => ( + + {price.product.name} +

+ {price.product.metadata.displayName} +

+

+ +

+
+ )) + } +
+
+
diff --git a/astro/src/pages/shop/index.astro b/astro/src/pages/shop/index.astro index 5fabb29..86e749a 100644 --- a/astro/src/pages/shop/index.astro +++ b/astro/src/pages/shop/index.astro @@ -1,11 +1,17 @@ --- +export const prerender = false + import { Image } from "@unpic/astro" import BaseLayout from "@layouts/BaseLayout.astro" -import LocalisedPrice from "@components/LocalisedPrice.astro" +import { getStripePrices } from "@utils/serverless" +import { getLocalCurrency } from "@utils/currency" +import { formatCurrency } from "@utils/intl" -import { getActivePrices } from "@utils/stripe" +const prices = await getStripePrices() -const prices = await getActivePrices() +const currency = getLocalCurrency( + Astro.locals.netlify.context.geo.country?.name +) ---

- + {formatCurrency({ + value: price.currency_options[currency] + .unit_amount, + currency, + })}

))