(null);
+
+ useEffect(() => {
+ if (typeof window === "undefined") {
+ return;
+ }
+
+ const updateRemainingTime = () => {
+ let article = articleElementRef.current;
+ if (!article) {
+ article = markerRef.current?.closest("article") as HTMLElement | null;
+ articleElementRef.current = article;
+ }
+ if (!article) {
+ setRemainingTime(totalMinutes);
+ return;
+ }
+
+ const articleRect = article.getBoundingClientRect();
+ if (articleRect.height <= 0) {
+ setRemainingTime(totalMinutes);
+ return;
+ }
+
+ const progress = calculateReadingProgress(articleRect);
+ const computedRemaining = Math.ceil(totalMinutes * (1 - progress));
+ setRemainingTime(Math.max(0, computedRemaining));
+ };
+
+ const handleScrollOrResize = () => {
+ if (animationFrameRef.current !== null) {
+ return;
+ }
+ animationFrameRef.current = window.requestAnimationFrame(() => {
+ animationFrameRef.current = null;
+ updateRemainingTime();
+ });
+ };
+
+ updateRemainingTime();
+ window.addEventListener("scroll", handleScrollOrResize, {passive: true});
+ window.addEventListener("resize", handleScrollOrResize);
+
+ return () => {
+ window.removeEventListener("scroll", handleScrollOrResize);
+ window.removeEventListener("resize", handleScrollOrResize);
+ if (animationFrameRef.current !== null) {
+ window.cancelAnimationFrame(animationFrameRef.current);
+ }
+ };
+ }, [totalMinutes]);
+
+ return {remainingTimePlural(remainingTime)};
+}
+
+export default function BlogPostItemHeaderInfo({className}: Props): ReactNode {
+ const {metadata, isBlogPostPage} = useBlogPost();
+ const {date, readingTime} = metadata;
+ const readingTimePlural = useReadingTimePlural();
+
+ const dateTimeFormat = useDateTimeFormat({
+ day: "numeric",
+ month: "long",
+ year: "numeric",
+ timeZone: "UTC",
+ });
+
+ const formatDate = (blogDate: string) =>
+ dateTimeFormat.format(new Date(blogDate));
+
+ return (
+
+
+ {typeof readingTime !== "undefined" && (
+ <>
+
+ {readingTimePlural(readingTime)}
+ {isBlogPostPage && (
+ <>
+
+
+ >
+ )}
+ >
+ )}
+
+ );
+}
diff --git a/src/theme/BlogPostItem/Header/Info/styles.module.css b/src/theme/BlogPostItem/Header/Info/styles.module.css
new file mode 100644
index 00000000..27d569e0
--- /dev/null
+++ b/src/theme/BlogPostItem/Header/Info/styles.module.css
@@ -0,0 +1,3 @@
+.container {
+ font-size: 0.9rem;
+}