From e79ea0a15e4b645f993c5c7820201fce3efb9311 Mon Sep 17 00:00:00 2001 From: Daveed Date: Wed, 30 Oct 2024 11:54:00 -0400 Subject: [PATCH] Gernated pages dynamically --- src/components/Footer.astro | 4 +- src/content/config.ts | 32 ++-------- src/interfaces/Page.ts | 4 ++ src/interfaces/index.ts | 5 ++ src/pages/[slug].astro | 48 +++++++++++++++ src/pages/about.astro | 46 -------------- src/pages/index.astro | 117 ++++++++++++++++++------------------ tsconfig.json | 7 ++- 8 files changed, 126 insertions(+), 137 deletions(-) create mode 100644 src/interfaces/index.ts create mode 100644 src/pages/[slug].astro delete mode 100644 src/pages/about.astro diff --git a/src/components/Footer.astro b/src/components/Footer.astro index 887d810..4137dad 100644 --- a/src/components/Footer.astro +++ b/src/components/Footer.astro @@ -16,9 +16,9 @@ const { noMarginTop = false } = Astro.props; diff --git a/src/content/config.ts b/src/content/config.ts index 1f521cc..8f2444e 100644 --- a/src/content/config.ts +++ b/src/content/config.ts @@ -1,11 +1,9 @@ -import { SITE, markketplace } from "@config"; -import { defineCollection, z } from "astro:content"; +import { markketplace } from "@config"; +import { defineCollection } from "astro:content"; import { strapiLoader } from "../lib/strapi-loader"; -// Define the Strapi posts collection -// This sets up a custom loader for Strapi content -const strapiPosts = defineCollection({ +const posts = defineCollection({ loader: strapiLoader({ contentType: "article", filter: `filters[store][slug][$eq]=${markketplace.STORE_SLUG}` }), }); @@ -17,26 +15,4 @@ const stores = defineCollection({ loader: strapiLoader({ contentType: "store", filter: `filters[slug][$eq]=${markketplace.STORE_SLUG}` }), }); -const blog = defineCollection({ - type: "content", - schema: ({ image }) => - z.object({ - author: z.string().default(SITE.author), - pubDatetime: z.date(), - modDatetime: z.date().optional().nullable(), - title: z.string(), - featured: z.boolean().optional(), - draft: z.boolean().optional(), - tags: z.array(z.string()).default(["others"]), - ogImage: image() - .refine(img => img.width >= 1200 && img.height >= 630, { - message: "OpenGraph image must be at least 1200 X 630 pixels!", - }) - .or(z.string()) - .optional(), - description: z.string(), - canonicalURL: z.string().optional(), - }), -}); - -export const collections = { blog, strapiPosts, pages, stores }; +export const collections = { posts, pages, stores }; diff --git a/src/interfaces/Page.ts b/src/interfaces/Page.ts index 8c0478e..8962861 100644 --- a/src/interfaces/Page.ts +++ b/src/interfaces/Page.ts @@ -26,6 +26,10 @@ export default interface Page { } } }, + SEO: { + metaDescription: string, + metaTitle: string, + }, createdAt: string; updatedAt: string; publishedAt: string; diff --git a/src/interfaces/index.ts b/src/interfaces/index.ts new file mode 100644 index 0000000..6e78b65 --- /dev/null +++ b/src/interfaces/index.ts @@ -0,0 +1,5 @@ +import type Store from './Store'; +import type Page from './Page'; +import type Product from './Product'; + +export type { Store, Page, Product }; diff --git a/src/pages/[slug].astro b/src/pages/[slug].astro new file mode 100644 index 0000000..101fb21 --- /dev/null +++ b/src/pages/[slug].astro @@ -0,0 +1,48 @@ +--- +import { type CollectionEntry, getCollection } from "astro:content"; +import type { Page, Store } from "@interfaces/index"; +import { + BlocksRenderer, + type BlocksContent, +} from "@strapi/blocks-react-renderer"; +import Layout from "@layouts/Layout.astro"; +import Header from "@components/Header.astro"; +import Footer from "@components/Footer.astro"; +import Breadcrumbs from "@components/Breadcrumbs.astro"; +import Hr from "@components/Hr.astro"; + +export interface Props { + page: CollectionEntry<"page">; +} + +export async function getStaticPaths() { + const pages = await getCollection("pages"); + + return pages.map((page: { data: CollectionEntry<"page"> }) => ({ + params: { slug: page.data.slug }, + props: { page: page.data }, + })); +} + +const stores = await getCollection("stores"); +const store = stores?.[0]?.data as unknown as Store; + +const { page } = Astro.props; +--- + + +
+ + +
+
+

{page.Title}

+
+ +
+ +
+
+
+ +