diff --git a/src/pages/categories/[category]/[...page].astro b/src/pages/categories/[category]/[...page].astro new file mode 100644 index 0000000..e8990b7 --- /dev/null +++ b/src/pages/categories/[category]/[...page].astro @@ -0,0 +1,74 @@ +--- +import type { CollectionEntry } from "astro:content"; +import Pagination from "@/components/Paginator.astro"; +import PostPreview from "@/components/blog/PostPreview.astro"; +import { getAllPosts, getUniqueCategories } from "@/data/post"; +import PageLayout from "@/layouts/Base.astro"; +import { collectionDateSort } from "@/utils/date"; +import type { GetStaticPaths, Page } from "astro"; + +export const getStaticPaths: GetStaticPaths = async ({ paginate }) => { + const allPosts = await getAllPosts(); + const sortedPosts = allPosts.sort(collectionDateSort); + const uniqueCategories = getUniqueCategories(sortedPosts); + + return uniqueCategories.flatMap((category) => { + const filterPosts = sortedPosts.filter((post) => post.data.category === category); + return paginate(filterPosts, { + pageSize: 20, + params: { category }, + }); + }); +}; + +interface Props { + page: Page>; +} + +const { page } = Astro.props; +const { category } = Astro.params; + +const meta = { + description: `View all posts with the category - ${category}`, + title: `Category: ${category}`, +}; + +const paginationProps = { + ...(page.url.prev && { + prevUrl: { + text: "← Previous Categories", + url: page.url.prev, + }, + }), + ...(page.url.next && { + nextUrl: { + text: "Next Categories →", + url: page.url.next, + }, + }), +}; +--- + + +
+

Posts with the category {category}

+ All {" "}Categories + + +
+
+

Post List

+
    + { + page.data.map((p) => ( +
  • + +
  • + )) + } +
+ +
+
diff --git a/src/pages/categories/index.astro b/src/pages/categories/index.astro new file mode 100644 index 0000000..885a65f --- /dev/null +++ b/src/pages/categories/index.astro @@ -0,0 +1,35 @@ +--- +import { getAllPosts, getUniqueCategoriesWithCount } from "@/data/post"; +import PageLayout from "@/layouts/Base.astro"; + +const allPosts = await getAllPosts(); +const allCategories = getUniqueCategoriesWithCount(allPosts); + +const meta = { + description: "A list of all the categories I've written about in my posts", + title: "All Categories", +}; +--- + + +

Categories

+ +
diff --git a/src/pages/category/[category]/[...page].astro b/src/pages/category/[category]/[...page].astro deleted file mode 100644 index 0fa2b0d..0000000 --- a/src/pages/category/[category]/[...page].astro +++ /dev/null @@ -1,23 +0,0 @@ ---- -import { getAllPosts, getUniqueCategories } from "@/data/post"; -import { collectionDateSort } from "@/utils/date"; -import type { GetStaticPaths } from "astro"; - -export const getStaticPaths: GetStaticPaths = async ({ paginate }) => { - const allPosts = await getAllPosts(); - const sortedPosts = allPosts.sort(collectionDateSort); - const uniqueCategories = getUniqueCategories(sortedPosts); - - return uniqueCategories.flatMap((category) => { - const filterPosts = sortedPosts.filter((post) => post.data.category === category); - return paginate(filterPosts, { - pageSize: 20, - params: { category }, - }); - }); -}; - -const currentPath = Astro.url.pathname; -const newPath = currentPath.replace("/category/", "/categories/"); -return Astro.redirect(newPath); ---- diff --git a/src/pages/category/index.astro b/src/pages/category/index.astro deleted file mode 100644 index ec0cff5..0000000 --- a/src/pages/category/index.astro +++ /dev/null @@ -1,3 +0,0 @@ ---- -return Astro.redirect("/categories"); ----