From f16f6d6b4c52ef1110ed0ea59acd61d7f0420ab0 Mon Sep 17 00:00:00 2001 From: Greg Date: Tue, 20 May 2025 21:49:53 +0200 Subject: [PATCH] debug --- src/content/config.ts | 20 ++++++++++++++++++++ src/pages/index.astro | 32 ++++++++++++++++++-------------- vite.config.js | 10 ++++++++++ 3 files changed, 48 insertions(+), 14 deletions(-) create mode 100644 src/content/config.ts diff --git a/src/content/config.ts b/src/content/config.ts new file mode 100644 index 0000000..337a09f --- /dev/null +++ b/src/content/config.ts @@ -0,0 +1,20 @@ +import { defineCollection, z } from 'astro:content'; + +const booksCollection = defineCollection({ + type: 'content', // 'content' for Markdown, 'data' for JSON/YAML + schema: z.object({ + title: z.string(), + author: z.string(), + year: z.number(), + genre: z.string(), + rating: z.number(), + cover: z.string(), // Assuming this is a path to an image + // The main body of the Markdown file (the description) + // doesn't need to be defined in the schema here; + // Astro handles it automatically. + }), +}); + +export const collections = { + 'books': booksCollection, +}; diff --git a/src/pages/index.astro b/src/pages/index.astro index 562c4aa..f8bb827 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -1,23 +1,27 @@ --- import Layout from "../layouts/Layout.astro"; -import fs from 'fs'; -import path from 'path'; +import { getCollection } from 'astro:content'; + +// Fetch all entries from the 'books' collection +const allBooks = await getCollection('books'); -// Dynamically import all markdown files from the books directory -const booksDirectory = "../content/books"; -const books = Object.values(import.meta.glob("../content/books/*.md", { eager: true })).map((mod) => mod.frontmatter); --- -

Book List

-
- {books.map(book => ( -
- {book.title -

{book.title}

-

by {book.author} ({book.year})

-

{book.genre} • Rating: {book.rating}

-

{book.description || ''}

+

My Book List

+
+ {allBooks.map(book => ( +
+ {`${book.data.title} +

{book.data.title}

+

by {book.data.author} ({book.data.year})

+

{book.data.genre} • Rating: {book.data.rating}/5

+ {/* Accessing the Markdown body for the description */} +

{book.body}

))}
diff --git a/vite.config.js b/vite.config.js index 67c4377..d6169a3 100644 --- a/vite.config.js +++ b/vite.config.js @@ -5,5 +5,15 @@ export default { // Example: If you had other Vite plugins or very specific Vite-only settings, // they would go here. // For now, it's minimal as Astro manages common settings. + + // Explicitly adding allowedHosts for Vite preview to address Coolify "Blocked request" + preview: { + allowedHosts: [ + 'fwo4c4cgkos8k8kk8ow44kcc.reflectonai.com', + 'localhost' // It's good practice to keep localhost if you test locally + ] + // Note: host and port are managed by Astro's `astro preview` command + // and astro.config.mjs, so we don't need to set them here again. + } };