-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
group posts by year works, now handle route params and PostCardSmall
- Loading branch information
Showing
13 changed files
with
106 additions
and
31 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
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
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
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
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,26 @@ | ||
import { getEntryLastDate } from '@/modules/common'; | ||
|
||
import type { Post, PostsByYear } from '@/types/post'; | ||
|
||
export const groupPostsByYear = (sortedPosts: Post[]): PostsByYear => { | ||
const postsByYear: PostsByYear = { | ||
years: [], | ||
posts: {}, | ||
}; | ||
|
||
const groupedPosts = sortedPosts.reduce((result, post) => { | ||
const postDate = getEntryLastDate(post); | ||
const year = postDate.getFullYear().toString(); | ||
|
||
if (!result.posts[year]) { | ||
result.years.push(year); | ||
result.posts[year] = []; | ||
} | ||
|
||
result.posts[year].push(post); | ||
|
||
return result; | ||
}, postsByYear); | ||
|
||
return groupedPosts; | ||
}; |
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
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
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,52 @@ | ||
--- | ||
import { getAllPostsWithReadingTime } from '@/modules/post/common'; | ||
import { groupPostsByYear } from '@/modules/post/group-by-year'; | ||
import List from '@/layouts/List.astro'; | ||
import CategoriesAndTags from '@/components/CategoriesAndTags.astro'; | ||
import { CONFIG } from '@/config'; | ||
import { getPageMetadata } from '@/utils/metadata'; | ||
import { pickPaginationPropsFromPage } from '@/utils/pagination'; | ||
import type { Post } from '@/types/post'; | ||
import type { GetStaticPathsOptions } from 'astro'; | ||
export async function getStaticPaths({ paginate }: GetStaticPathsOptions) { | ||
const posts: Post[] = await getAllPostsWithReadingTime(); | ||
// filter by tag and category here | ||
// must have grouped here for pagination // no need | ||
const pagination = paginate(posts, { pageSize: CONFIG.PAGE_SIZE }); | ||
pagination.push({ params: { page: '1' }, props: pagination[0].props }); | ||
return pagination; | ||
} | ||
const { page } = Astro.props; | ||
const { data: posts } = page; | ||
// for categories and tags | ||
const allPosts = await getAllPostsWithReadingTime(); | ||
const postsByYear = groupPostsByYear(posts); | ||
const paginationProps = pickPaginationPropsFromPage(page); | ||
const metadata = getPageMetadata('lists/blog/categories-and-tags'); | ||
const layoutProps = { metadata, paginationProps }; | ||
--- | ||
|
||
<List {...layoutProps}> | ||
<CategoriesAndTags posts={allPosts} /> | ||
{ | ||
postsByYear.years.map((year) => ( | ||
<> | ||
<h2 class="title text-lg">{year}</h2> | ||
<ul class="mb-8 mt-6 space-y-8"> | ||
{postsByYear.posts[year].map((post) => ( | ||
<li class="">{post.data.title}</li> | ||
))} | ||
</ul> | ||
</> | ||
)) | ||
} | ||
</List> |
This file was deleted.
Oops, something went wrong.
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
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
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
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