diff --git a/blog/src/components/PostGrid.astro b/blog/src/components/PostGrid.astro index 99277f7..d81a4af 100644 --- a/blog/src/components/PostGrid.astro +++ b/blog/src/components/PostGrid.astro @@ -1,9 +1,8 @@ --- -import type { Post } from "../types/global"; import PostPreviewSmall from "./PostPreviewSmall.astro"; interface Props { - posts: Array; + posts: Array; } const { posts } = Astro.props; @@ -12,7 +11,7 @@ const { posts } = Astro.props;
{ posts.map((post_file: any) => ( - + )) }
diff --git a/blog/src/components/PostPreviewLarge.astro b/blog/src/components/PostPreviewLarge.astro index 6ae8110..3ff1b33 100644 --- a/blog/src/components/PostPreviewLarge.astro +++ b/blog/src/components/PostPreviewLarge.astro @@ -1,15 +1,14 @@ --- -import type { Post } from "../types/global"; import { findImageByPath } from "../lib/findImage"; import { Image } from "astro:assets"; import { formatLocalizedDateString } from "../lib/formatDate"; +import type { PostData } from "../content.config"; interface Props { - post: Post; - url: string; + post: PostData; } -const { post, url } = Astro.props; +const { post } = Astro.props; const img = findImageByPath(post.image.path); const localeDate = formatLocalizedDateString(post.date) @@ -17,12 +16,12 @@ const localeDate = formatLocalizedDateString(post.date)
- +

{post.title}

{post.subtitle} diff --git a/blog/src/components/PostPreviewSmall.astro b/blog/src/components/PostPreviewSmall.astro index af28c0b..a99faab 100644 --- a/blog/src/components/PostPreviewSmall.astro +++ b/blog/src/components/PostPreviewSmall.astro @@ -1,21 +1,19 @@ --- - +import type { PostData } from "../content.config"; import { findImageByPath } from "../lib/findImage"; import { formatLocalizedDateString } from "../lib/formatDate"; -import type { Post } from "../types/global"; interface Props { - post: Post; - url: string; + post: PostData; } -const { post, url } = Astro.props; +const { post } = Astro.props; const img = findImageByPath(post.image.path) const localeDate = formatLocalizedDateString(post.date) --- - +
{post.image.alt}

{post.title}

diff --git a/blog/src/content.config.ts b/blog/src/content.config.ts new file mode 100644 index 0000000..030b763 --- /dev/null +++ b/blog/src/content.config.ts @@ -0,0 +1,29 @@ +import { defineCollection } from 'astro:content'; +import { glob } from 'astro/loaders'; +import { z } from 'astro/zod'; + + +const postSchema = z.object({ + title: z.string(), + subtitle: z.string(), + description: z.string(), + image: z.object({ + path: z.string(), + alt: z.string() + }), + author: z.string(), + date: z.coerce.date(), + slug: z.string(), +}); + +export type PostData = z.infer; + +const posts = defineCollection({ + loader: glob({ + pattern: "**/*.md", + base: "./src/pages/blog/", + }), + schema: postSchema +}); + +export const collections = { posts }; \ No newline at end of file diff --git a/blog/src/layouts/BlogPostLayout.astro b/blog/src/layouts/BlogPostLayout.astro index ce94df2..bae2d93 100644 --- a/blog/src/layouts/BlogPostLayout.astro +++ b/blog/src/layouts/BlogPostLayout.astro @@ -2,12 +2,12 @@ import { Image } from "astro:assets"; import BackNav from "../components/BackNav.astro"; import { findImageByPath } from "../lib/findImage"; -import type { Post } from "../types/global"; import Main from "./Main.astro"; import { formatLocalizedDateString } from "../lib/formatDate"; +import type { PostData } from "../content.config"; interface Props { - frontmatter: Post; + frontmatter: PostData; } const { frontmatter } = Astro.props; diff --git a/blog/src/lib/formatDate.ts b/blog/src/lib/formatDate.ts index 7108707..c517964 100644 --- a/blog/src/lib/formatDate.ts +++ b/blog/src/lib/formatDate.ts @@ -1,3 +1,3 @@ -export function formatLocalizedDateString(date: string): string { - return new Date(date).toLocaleDateString('de-DE') +export function formatLocalizedDateString(date: Date): string { + return date.toLocaleDateString('de-DE') } \ No newline at end of file diff --git a/blog/src/pages/posts/1_Under_Construction.md b/blog/src/pages/blog/1_Under_Construction.md similarity index 95% rename from blog/src/pages/posts/1_Under_Construction.md rename to blog/src/pages/blog/1_Under_Construction.md index c05c8a9..befd4fe 100644 --- a/blog/src/pages/posts/1_Under_Construction.md +++ b/blog/src/pages/blog/1_Under_Construction.md @@ -1,12 +1,14 @@ --- layout: ../../layouts/BlogPostLayout.astro title: Under Construction +subtitle: Wir bauen für Sie description: Bald könnt ihr hier unsere ersten Abenteuer mitverfolgen. Und keine Sorge...an der Webseite wird auch noch gearbeitet! image: path: construction.png alt: Under Construction author: Tim date: '2026-07-10' +slug: Under-Construction --- # All Endings Are Beginnings diff --git a/blog/src/pages/posts/2_Ostseeurlaub.md b/blog/src/pages/blog/2_Ostseeurlaub.md similarity index 99% rename from blog/src/pages/posts/2_Ostseeurlaub.md rename to blog/src/pages/blog/2_Ostseeurlaub.md index fbac87c..ebb0c07 100644 --- a/blog/src/pages/posts/2_Ostseeurlaub.md +++ b/blog/src/pages/blog/2_Ostseeurlaub.md @@ -8,6 +8,7 @@ image: alt: Chiara und Tim vor einem Strand author: Tim date: '2026-08-20' +slug: Ostseeurlaub --- Eigentlich soll es hier um unser (zukünftiges) Boot und die Segelreisen gehen. diff --git a/blog/src/pages/posts/3_Matrei.md b/blog/src/pages/blog/3_Matrei.md similarity index 99% rename from blog/src/pages/posts/3_Matrei.md rename to blog/src/pages/blog/3_Matrei.md index 8b39617..45759b8 100644 --- a/blog/src/pages/posts/3_Matrei.md +++ b/blog/src/pages/blog/3_Matrei.md @@ -8,6 +8,7 @@ image: alt: Chiara und Tim in der nähe der Bergeralm mit tollen Bergen im Hintergrund. author: Tim date: '2026-08-29' +slug: Luxusurlaub-in-Matrei --- Was könnte ein besser Kontrast zum Zelturlaub an der Ostsee sein, als eine Woche in einem luxuriösen Hotel, mitten in den Alpen?
diff --git a/blog/src/pages/blog/[slug].astro b/blog/src/pages/blog/[slug].astro new file mode 100644 index 0000000..591a794 --- /dev/null +++ b/blog/src/pages/blog/[slug].astro @@ -0,0 +1,24 @@ +--- +import { getCollection, render } from "astro:content"; +import BlogPostLayout from "../../layouts/BlogPostLayout.astro"; + +export async function getStaticPaths() { + const posts = await getCollection("posts"); + + return posts.map((post) => ({ + params: { + slug: post.data.slug, + }, + props: { + post, + }, + })); +} + +const { post } = Astro.props; +const { Content } = await render(post); +--- + + + + diff --git a/blog/src/pages/index.astro b/blog/src/pages/index.astro index 8e9dd03..f69bc82 100644 --- a/blog/src/pages/index.astro +++ b/blog/src/pages/index.astro @@ -2,32 +2,21 @@ import Main from "../layouts/Main.astro"; import PostPreviewLarge from "../components/PostPreviewLarge.astro"; import PostGrid from "../components/PostGrid.astro"; -import type { Post } from "../types/global"; -import { date, readonly } from "astro:schema"; +import { getCollection } from "astro:content"; -const allPosts: Array = Object.values( - import.meta.glob("./posts/*.md", { eager: true }) +const allPostsSorted = (await getCollection('posts')).sort( + (postA, postB) => + postB.data.date.getTime() - postA.data.date.getTime() ); -const sortedPosts = allPosts.slice(0, allPosts.length - 1) - .sort((postA: any, postB: any): number => { - const dateA = new Date(postA.frontmatter.date) - const dateB = new Date(postB.frontmatter.date) +const [mostRecentPost, ...sortedPosts] = allPostsSorted; - if (dateA > dateB) return -1 - else if (dateA < dateB) return 1 - return 0 -}) - - - -const mostRecentPost = allPosts.at(allPosts.length - 1); +console.log(mostRecentPost.data) ---
diff --git a/blog/src/pages/rss.xml.js b/blog/src/pages/rss.xml.js index ddd9ad7..39917f7 100644 --- a/blog/src/pages/rss.xml.js +++ b/blog/src/pages/rss.xml.js @@ -3,7 +3,7 @@ import rss, { pagesGlobToRssItems } from '@astrojs/rss'; export async function GET(context) { const posts = Object.values( - import.meta.glob("./posts/*.md", { eager: true }) + import.meta.glob("./blog/*.md", { eager: true }) ); return rss({ @@ -15,7 +15,7 @@ export async function GET(context) { subtitle: post.frontmatter.subtitle, pubDate: Date.parse(post.frontmatter.date), description: post.frontmatter.description, - link: post.url, + link: `/blog/${post.frontmatter.slug}` })), customData: `de-de`, }); diff --git a/blog/src/types/global.ts b/blog/src/types/global.ts index 002d843..e69de29 100644 --- a/blog/src/types/global.ts +++ b/blog/src/types/global.ts @@ -1,11 +0,0 @@ -export interface Post { - title: String, - subtitle: String, - description: String, - date: string, - author: String, - image: { - path: string, - alt: string - } -} \ No newline at end of file