/** * 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 clsx from 'clsx'; import Translate, {translate} from '@docusaurus/Translate'; import Link from '@docusaurus/Link'; import {useBaseUrlUtils} from '@docusaurus/useBaseUrl'; import {usePluralForm} from '@docusaurus/theme-common'; import {blogPostContainerID} from '@docusaurus/utils-common'; import MDXContent from '@theme/MDXContent'; import EditThisPage from '@theme/EditThisPage'; import TagsListInline from '@theme/TagsListInline'; import BlogPostAuthors from '@theme/BlogPostAuthors'; import type {Props} from '@theme/BlogPostItem'; import styles from './styles.module.css'; // Very simple pluralization: probably good enough for now function useReadingTimePlural() { const {selectMessage} = usePluralForm(); return (readingTimeFloat: number) => { const readingTime = Math.ceil(readingTimeFloat); return selectMessage( readingTime, translate( { id: 'theme.blog.post.readingTime.plurals', description: 'Pluralized label for "{readingTime} min read". Use as much plural forms (separated by "|") as your language support (see https://www.unicode.org/cldr/cldr-aux/charts/34/supplemental/language_plural_rules.html)', message: 'One min read|{readingTime} min read', }, {readingTime}, ), ); }; } export default function BlogPostItem(props: Props): JSX.Element { const readingTimePlural = useReadingTimePlural(); const {withBaseUrl} = useBaseUrlUtils(); const { children, frontMatter, assets, metadata, truncated, isBlogPostPage = false, } = props; const { date, formattedDate, permalink, tags, readingTime, title, editUrl, authors, } = metadata; const image = assets.image ?? frontMatter.image; const truncatedPost = !isBlogPostPage && truncated; const tagsExists = tags.length > 0; const TitleHeading = isBlogPostPage ? 'h1' : 'h2'; return (
{isBlogPostPage ? ( title ) : ( {title} )}
{typeof readingTime !== 'undefined' && ( <> {' ยท '} {readingTimePlural(readingTime)} )}
{image && ( )}
{children}
{(tagsExists || truncated || editUrl) && ( )}
); }