Skip to content

Commit

Permalink
Parse dates at fetch time
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobwgillespie committed May 8, 2024
1 parent 465d151 commit dfc5177
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
10 changes: 7 additions & 3 deletions src/components/Item.astro
@@ -1,13 +1,13 @@
---
import {formatDistanceToNow, parseISO} from 'date-fns'
import {formatDistanceToNow} from 'date-fns'
import type {FeedItem} from '../utils/feed'
interface Props {
item: FeedItem
}
const {item} = Astro.props
const timeAgo = `${formatDistanceToNow(parseISO(item.date))} ago`
const timeAgo = `${formatDistanceToNow(item.date)} ago`
---

<div class="flex flex-col items-baseline gap-1 leading-none md:flex-row">
Expand All @@ -33,7 +33,11 @@ const timeAgo = `${formatDistanceToNow(parseISO(item.date))} ago`
</a>
)
}
<time datetime={item.date} title={item.date} class="whitespace-nowrap text-sm text-stone-500">
<time
datetime={item.date.toISOString()}
title={item.date.toISOString()}
class="whitespace-nowrap text-sm text-stone-500"
>
{timeAgo}
</time>
</div>
5 changes: 2 additions & 3 deletions src/utils/feed.ts
@@ -1,12 +1,11 @@
import {parseISO} from 'date-fns'
import {Feed} from 'feed'
import {fetchFeedbinEntries} from './feedbin'

export interface FeedItem {
id: string
title: string
link: string
date: string
date: Date
content?: string
hn: string | false
lobsters: string | false
Expand Down Expand Up @@ -52,7 +51,7 @@ export async function buildFeed(items: FeedItem[]) {
title: item.title,
guid: item.id,
link: item.link,
date: parseISO(item.date),
date: item.date,
content: item.content ?? '',
})
}
Expand Down
3 changes: 2 additions & 1 deletion src/utils/feedbin.ts
@@ -1,4 +1,5 @@
import DataLoader from 'dataloader'
import {parseISO} from 'date-fns'
import type {FeedItem} from './feed'

/** ID of the Hacker News feed in Feedbin */
Expand Down Expand Up @@ -69,7 +70,7 @@ export async function fetchFeedbinEntries(env: Env): Promise<FeedItem[]> {
id: `https://feedbin.me/entries/${entry.id}`,
title: entry.title,
link: entry.url,
date: entry.published,
date: parseISO(entry.published),
content: entry.content,
hn,
lobsters,
Expand Down

0 comments on commit dfc5177

Please sign in to comment.