/** * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ import React from 'react'; import Layout from '@theme/Layout'; import Link from '@docusaurus/Link'; import type {ArchiveBlogPost, Props} from '@theme/BlogArchivePage'; import {translate} from '@docusaurus/Translate'; type YearProp = { year: string; posts: ArchiveBlogPost[]; }; function Year({year, posts}: YearProp) { return ( <>

{year}

); } function YearsSection({years}: {years: YearProp[]}) { return (
{years.map((_props, idx) => (
))}
); } function listPostsByYears(blogPosts: readonly ArchiveBlogPost[]): YearProp[] { const postsByYear: Map = blogPosts.reduceRight( (posts, post) => { const year = post.metadata.date.split('-')[0]; const yearPosts = posts.get(year) || []; return posts.set(year, [post, ...yearPosts]); }, new Map(), ); return Array.from(postsByYear, ([year, posts]) => ({ year, posts, })); } export default function BlogArchive({archive}: Props): JSX.Element { const title = translate({ id: 'theme.blog.archive.title', message: 'Archive', description: 'The page & hero title of the blog archive page', }); const description = translate({ id: 'theme.blog.archive.description', message: 'Archive', description: 'The page & hero description of the blog archive page', }); const years = listPostsByYears(archive.blogPosts); return (

{title}

{description}

{years.length > 0 && }
); }