diff --git a/src/components/Post.astro b/src/components/Post.astro index aa4d8d8..dffc42b 100644 --- a/src/components/Post.astro +++ b/src/components/Post.astro @@ -2,19 +2,17 @@ import { render, getCollection, type CollectionEntry } from "astro:content"; interface Props { - post: CollectionEntry<"blog">; + post: CollectionEntry<"posts">; componentType: "short" | "long" | "full"; } const { post, componentType } = Astro.props; -const categories = await getCollection("categories"); - const categoryTitles = await Promise.all( post.data.categories.map(async (c) => await getEntry("categories", c.id)) ); -console.log(categoryTitles); +const parentCategory = categoryTitles.find((c) => !Boolean(c?.data.parent?.id)); // default options for the post component const deafultOptions = { @@ -55,7 +53,7 @@ const postDateFormatted = post.data.date.toLocaleDateString("tr-TR", { }); // Create post link -const postLink = `/${post.data.category}/${post.slug}`; +const postLink = `/${parentCategory?.data.slug}/${post.data.slug}`; // Create post content as an astro component const { Content } = await render(post); diff --git a/src/pages/[category]/[slug]/index.astro b/src/pages/[category]/[slug]/index.astro index b698b29..ac24fe6 100644 --- a/src/pages/[category]/[slug]/index.astro +++ b/src/pages/[category]/[slug]/index.astro @@ -1,5 +1,5 @@ --- -import { getCollection } from "astro:content"; +import { getCollection, getEntry } from "astro:content"; import Footer from "@/components/Footer.astro"; import Header from "@/components/Header.astro"; @@ -8,7 +8,6 @@ import Post from "@/components/Post.astro"; import EmojiReactionForm from "@/components/EmojiReactionForm.astro"; import CommentForm from "@/components/CommentForm.astro"; import HorizontalLine from "@/components/HorizontalLine.astro"; -import BookReview from "@/components/BookReview.astro"; const { entry } = Astro.props; @@ -17,33 +16,37 @@ const URL = Astro.url; const backendHost = import.meta.env.PUBLIC_BACKEND_HOST; export async function getStaticPaths() { - const blogEntries = await getCollection("blog"); - const allReviews = await getCollection("bookReview"); + const posts = await getCollection("posts"); - const allPosts = [...allReviews, ...blogEntries].filter( - (post) => !post.data.draft + return await Promise.all( + posts.map(async (entry) => { + const categoryTitles = await Promise.all( + entry.data.categories.map( + async (c) => await getEntry("categories", c.id) + ) + ); + + const parentCategory = categoryTitles.find( + (c) => !Boolean(c?.data.parent?.id) + ); + + return { + params: { category: parentCategory?.data.slug, slug: entry.data.slug }, + props: { entry }, + }; + }) ); - - return allPosts.map((entry) => ({ - params: { category: entry.data.category, slug: entry.slug }, - props: { entry }, - })); } ---
- { - entry.collection === "blog" ? ( - - ) : ( - - ) - } + +
diff --git a/src/pages/admin.html b/src/pages/admin.html deleted file mode 100644 index a157da2..0000000 --- a/src/pages/admin.html +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - Content Manager - - - - - - diff --git a/src/pages/index.astro b/src/pages/index.astro index 5407388..1ccf5a3 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -5,23 +5,15 @@ import Layout from "@/layouts/Layout.astro"; import { getCollection } from "astro:content"; import Post from "@/components/Post.astro"; -import BookReview from "@/components/BookReview.astro"; -import { Picture } from "astro:assets"; -const allTeknikPosts = await getCollection("blog"); -const allReviews = await getCollection("bookReview"); -const allWpPosts = await getCollection("posts"); - -const allPosts = [...allReviews, ...allTeknikPosts].filter( - (post) => !post.data.draft -); +const posts = await getCollection("posts"); ---
{ - allWpPosts + posts .sort((p1, p2) => p2.data.date.getTime() - p1.data.date.getTime()) .map((p) => ) }