mirror of
https://github.com/jakejarvis/jarv.is.git
synced 2025-09-18 16:05:33 -04:00
move some non-post pages to mdx
This commit is contained in:
@@ -1,22 +1,22 @@
|
||||
"use client";
|
||||
|
||||
import useHasMounted from "../../hooks/useHasMounted";
|
||||
import { useHasMounted } from "../../hooks";
|
||||
import { formatDate, formatTimeAgo } from "../../lib/helpers/format-date";
|
||||
import type { ComponentPropsWithoutRef } from "react";
|
||||
|
||||
export type RelativeTimeProps = {
|
||||
export type RelativeTimeProps = ComponentPropsWithoutRef<"time"> & {
|
||||
date: string | number | Date;
|
||||
verb?: string; // optional "Updated", "Published", "Created", etc.
|
||||
staticFormat?: string; // format for the placeholder/fallback before client-side renders the relative time
|
||||
className?: string;
|
||||
};
|
||||
|
||||
const RelativeTime = ({ date, verb, staticFormat, className }: RelativeTimeProps) => {
|
||||
const RelativeTime = ({ date, verb, staticFormat, ...rest }: RelativeTimeProps) => {
|
||||
// play nice with SSR -- only use relative time on the client, since it'll quickly become outdated on the server and
|
||||
// cause a react hydration mismatch error.
|
||||
const hasMounted = useHasMounted();
|
||||
|
||||
return (
|
||||
<time dateTime={formatDate(date)} title={formatDate(date, "MMM D, YYYY, h:mm A z")} className={className}>
|
||||
<time dateTime={formatDate(date)} title={formatDate(date, "MMM D, YYYY, h:mm A z")} {...rest}>
|
||||
{verb && `${verb} `}
|
||||
{hasMounted ? formatTimeAgo(date, { suffix: true }) : `on ${formatDate(date, staticFormat)}`}
|
||||
</time>
|
||||
|
Reference in New Issue
Block a user