@@ -4,12 +4,13 @@ import type { Lang, RSSItem } from "../types"
4
4
import { isValidDate } from "./date"
5
5
import { getLocaleTimestamp } from "./time"
6
6
7
- export const sortByPubDate = ( items : RSSItem [ ] ) =>
7
+ // Sort by original pubDate string (not yet localized)
8
+ export const sortByPubDateRaw = ( items : ( RSSItem & { pubDateRaw : string } ) [ ] ) =>
8
9
items . sort ( ( a , b ) => {
9
- const dateA = new Date ( a . pubDate )
10
- const dateB = new Date ( b . pubDate )
10
+ const dateA = new Date ( a . pubDateRaw )
11
+ const dateB = new Date ( b . pubDateRaw )
11
12
if ( isNaN ( dateA . getTime ( ) ) || isNaN ( dateB . getTime ( ) ) ) {
12
- console . error ( "Invalid date found:" , a . pubDate , b . pubDate )
13
+ console . error ( "Invalid date found:" , a . pubDateRaw , b . pubDateRaw )
13
14
return 0
14
15
}
15
16
return dateB . getTime ( ) - dateA . getTime ( )
@@ -20,7 +21,7 @@ export const postProcess = (rssItems: RSSItem[], locale: Lang) =>
20
21
const pubDate = isValidDate ( item . pubDate )
21
22
? getLocaleTimestamp ( locale , item . pubDate )
22
23
: ""
23
- const formattedItem = { ...item , pubDate }
24
+ const formattedItem = { ...item , pubDate, pubDateRaw : item . pubDate }
24
25
25
26
switch ( item . sourceFeedUrl ) {
26
27
case VITALIK_FEED :
@@ -47,5 +48,5 @@ export const polishRSSList = (items: RSSItem[][], locale: Lang) => {
47
48
48
49
const latestItems = latestOfEach . flat ( )
49
50
const readyForSorting = postProcess ( latestItems , locale )
50
- return sortByPubDate ( readyForSorting )
51
+ return sortByPubDateRaw ( readyForSorting )
51
52
}
0 commit comments