-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
--- | ||
import config from "@/config/config.json"; | ||
import Base from "@/layouts/Base.astro"; | ||
import Pagination from "@/layouts/components/Pagination.astro"; | ||
import Posts from "@/layouts/Posts.astro"; | ||
import { getSinglePage } from "@/lib/contentParser.astro"; | ||
import { sortByDate } from "@/lib/utils/sortFunctions"; | ||
export async function getStaticPaths() { | ||
const posts = await getSinglePage("posts"); | ||
const totalPages = Math.ceil(posts.length / config.settings.pagination); | ||
const paths = []; | ||
for (let i = 1; i < totalPages; i++) { | ||
paths.push({ | ||
params: { | ||
slug: (i + 1).toString(), | ||
}, | ||
}); | ||
} | ||
return paths; | ||
} | ||
const { slug } = Astro.params; | ||
const posts = await getSinglePage("posts"); | ||
const sortedPosts = sortByDate(posts); | ||
const totalPages = Math.ceil(posts.length / config.settings.pagination); | ||
const currentPage = slug && !isNaN(Number(slug)) ? Number(slug) : 1; | ||
const indexOfLastPost = currentPage * config.settings.pagination; | ||
const indexOfFirstPost = indexOfLastPost - config.settings.pagination; | ||
const currentPosts = sortedPosts.slice(indexOfFirstPost, indexOfLastPost); | ||
--- | ||
|
||
<Base> | ||
<section class="section"> | ||
<div class="container"> | ||
<Posts className="mb-16" posts={currentPosts} /> | ||
<Pagination totalPages={totalPages} currentPage={currentPage} /> | ||
</div> | ||
</section> | ||
</Base> |