stacker.news/lib/item.js

12 lines
394 B
JavaScript
Raw Normal View History

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