chore: fuzzy search for date key instead of control flow

This commit is contained in:
Cory Dransfeldt 2023-09-06 12:57:53 -07:00
parent 69a8dfc24f
commit 46db92b948
No known key found for this signature in database

View file

@ -25,18 +25,14 @@ module.exports = {
}, },
normalizeEntries: (entries) => { normalizeEntries: (entries) => {
return entries.map((entry) => { return entries.map((entry) => {
const dateKey = Object.keys(entry).find((key) => key.includes('date'))
const date = entry[dateKey]
let excerpt = '' let excerpt = ''
let date = ''
// set the entry excerpt // set the entry excerpt
if (entry.data?.post_excerpt) excerpt = entry.data.post_excerpt if (entry.data?.post_excerpt) excerpt = entry.data.post_excerpt
if (entry.description) excerpt = entry.description if (entry.description) excerpt = entry.description
// set the entry date
if (entry.date) date = entry.date
if (entry.dateAdded) date = entry.dateAdded
if (entry.date_published) date = entry.date_published
// if there's a valid entry return a normalized object // if there's a valid entry return a normalized object
if (entry) { if (entry) {
return { return {