@@ -144,16 +147,18 @@ export function ArticleView({ post }: ArticleViewProps) {
{displayName}
-
-
-
-
+ {validDate && (
+
+
+
+
+ )}
diff --git a/src/lib/date.ts b/src/lib/date.ts
new file mode 100644
index 0000000..97f7533
--- /dev/null
+++ b/src/lib/date.ts
@@ -0,0 +1,13 @@
+export function isValidDate(date: Date | null | undefined): boolean {
+ if (!date) return false;
+ return !isNaN(date.getTime());
+}
+
+export function toISOStringSafe(date: Date | null | undefined): string {
+ if (!isValidDate(date as Date)) return "";
+ try {
+ return (date as Date).toISOString();
+ } catch {
+ return "";
+ }
+}
diff --git a/src/pages/ArticlePage.tsx b/src/pages/ArticlePage.tsx
index d95926e..82bd466 100644
--- a/src/pages/ArticlePage.tsx
+++ b/src/pages/ArticlePage.tsx
@@ -7,6 +7,7 @@ import { ArticleView } from '@/components/ArticleView';
import { Skeleton } from '@/components/ui/skeleton';
import NotFound from '@/pages/NotFound';
import { genUserName } from '@/lib/genUserName';
+import { toISOStringSafe } from '@/lib/date';
export default function ArticlePage() {
const { nip19: naddr } = useParams<{ nip19: string }>();
@@ -71,11 +72,16 @@ export default function ArticlePage() {
ogImage: image || `${siteUrl}/icon-512.png`,
ogSiteName: 'zelo.news',
// Article-specific OG tags
- ...(post && isValidNaddr && {
- articlePublishedTime: date.toISOString(),
- articleAuthor: [authorName],
- ...(hashtags.length > 0 && { articleTag: hashtags }),
- }),
+ ...(post && isValidNaddr && (() => {
+ const iso = toISOStringSafe(date);
+ return iso
+ ? {
+ articlePublishedTime: iso,
+ articleAuthor: [authorName],
+ ...(hashtags.length > 0 && { articleTag: hashtags }),
+ }
+ : {};
+ })()),
// Twitter Card tags
twitterCard: 'summary_large_image',
twitterTitle: title,
diff --git a/src/pages/EventPage.tsx b/src/pages/EventPage.tsx
index c8a1687..b5727d2 100644
--- a/src/pages/EventPage.tsx
+++ b/src/pages/EventPage.tsx
@@ -13,6 +13,7 @@ import { ArrowLeft, Calendar, Hash } from 'lucide-react';
import { genUserName } from '@/lib/genUserName';
import type { NostrEvent } from '@nostrify/nostrify';
import NotFound from './NotFound';
+import { isValidDate, toISOStringSafe } from '@/lib/date';
interface EventPageProps {
eventId: string;
@@ -118,6 +119,7 @@ export function EventPage({ eventId, relayHints, authorPubkey, kind }: EventPage
}
const date = new Date(event.created_at * 1000);
+ const validDate = isValidDate(date);
return (
@@ -141,19 +143,21 @@ export function EventPage({ eventId, relayHints, authorPubkey, kind }: EventPage
Kind {event.kind}
-
+ {validDate && (
+
+ )}
@@ -145,18 +147,20 @@ export function NotePage({ eventId }: NotePageProps) {
{displayName}
-
+ {validDate && (
+
+ )}