Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/theme/BlogPostItem/Header/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React, {type ReactNode} from 'react';
import Header from '@theme-original/BlogPostItem/Header';
import type HeaderType from '@theme/BlogPostItem/Header';
import type {WrapperProps} from '@docusaurus/types';
import {useBlogPost} from '@docusaurus/plugin-content-blog/client';
import Admonition from '@theme/Admonition';

type Props = WrapperProps<typeof HeaderType>;

export default function HeaderWrapper(props: Props): ReactNode {
const { metadata: { date: postDate } } = useBlogPost();

const postAgeInYears = Math.floor((Date.now() - new Date(postDate).getTime()) / (1000 * 60 * 60 * 24 * 365));

const postIsOld = postAgeInYears >= 1;

return (
<>
{
postIsOld ? (
<Admonition type="warning">
<p>
This blog post is over { postAgeInYears } { postAgeInYears === 1 ? 'year' : 'years' } old.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This word copy can be adjusted as needed.

</p>
</Admonition>
) : null
}
<Header {...props} />
</>
);
}
Loading