This commit is contained in:
parent
844d31754d
commit
36870785bc
35 changed files with 1344 additions and 1330 deletions
|
@ -1,37 +1,39 @@
|
|||
---
|
||||
import BlogCard from '@/components/BlogCard.astro'
|
||||
import Breadcrumbs from '@/components/Breadcrumbs.astro'
|
||||
import Container from '@/components/Container.astro'
|
||||
import PaginationComponent from '@/components/ui/pagination'
|
||||
import { SITE } from '@/consts'
|
||||
import Layout from '@/layouts/Layout.astro'
|
||||
import type { PaginateFunction } from 'astro'
|
||||
import { type CollectionEntry, getCollection } from 'astro:content'
|
||||
import { type CollectionEntry, getCollection } from "astro:content";
|
||||
import BlogCard from "@/components/BlogCard.astro";
|
||||
import Breadcrumbs from "@/components/Breadcrumbs.astro";
|
||||
import Container from "@/components/Container.astro";
|
||||
import PaginationComponent from "@/components/ui/pagination";
|
||||
import { SITE } from "@/consts";
|
||||
import Layout from "@/layouts/Layout.astro";
|
||||
import type { PaginateFunction } from "astro";
|
||||
|
||||
export async function getStaticPaths({
|
||||
paginate,
|
||||
paginate,
|
||||
}: {
|
||||
paginate: PaginateFunction
|
||||
paginate: PaginateFunction;
|
||||
}) {
|
||||
const allPosts = await getCollection('blog', ({ data }) => !data.draft)
|
||||
return paginate(
|
||||
allPosts.sort((a, b) => b.data.date.valueOf() - a.data.date.valueOf()),
|
||||
{ pageSize: SITE.postsPerPage },
|
||||
)
|
||||
const allPosts = await getCollection("blog", ({ data }) => !data.draft);
|
||||
return paginate(
|
||||
allPosts.sort((a, b) => b.data.date.valueOf() - a.data.date.valueOf()),
|
||||
{ pageSize: SITE.postsPerPage },
|
||||
);
|
||||
}
|
||||
|
||||
const { page } = Astro.props
|
||||
const { page } = Astro.props;
|
||||
|
||||
const postsByYear = page.data.reduce(
|
||||
(acc: Record<string, CollectionEntry<'blog'>[]>, post) => {
|
||||
const year = post.data.date.getFullYear().toString()
|
||||
;(acc[year] ??= []).push(post)
|
||||
return acc
|
||||
},
|
||||
{},
|
||||
)
|
||||
(acc: Record<string, CollectionEntry<"blog">[]>, post) => {
|
||||
const year = post.data.date.getFullYear().toString();
|
||||
(acc[year] ??= []).push(post);
|
||||
return acc;
|
||||
},
|
||||
{},
|
||||
);
|
||||
|
||||
const years = Object.keys(postsByYear).sort((a, b) => parseInt(b) - parseInt(a))
|
||||
const years = Object.keys(postsByYear).sort(
|
||||
(a, b) => Number.parseInt(b) - Number.parseInt(a),
|
||||
);
|
||||
---
|
||||
|
||||
<Layout title="Blog" description="Blog">
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue