stacker.news/lib/item.js

12 lines
394 B
JavaScript
Raw Normal View History

import { OLD_ITEM_DAYS } from './constants'
2023-08-10 17:40:50 -05:00
import { datePivot } from './time'
export const defaultCommentSort = (pinned, bio, createdAt) => {
// pins sort by recent
2023-07-25 19:45:35 -05:00
if (pinned) return 'recent'
// old items (that aren't bios) sort by top
2023-08-10 17:35:11 -05:00
if (!bio && new Date(createdAt) < datePivot(new Date(), { days: -OLD_ITEM_DAYS })) return 'top'
// everything else sorts by hot
return 'hot'
}