Merge pull request #220 from acid-info/posts-sort

Posts sort
This commit is contained in:
amir houieh 2023-12-15 14:04:59 +01:00 committed by GitHub
commit 8657a4e95f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 5 deletions

2
.env
View File

@ -6,4 +6,4 @@ DISCORD_LOGS_WEBHOOK_URL=
NEXT_PUBLIC_SITE_URL=
FATHOM_SITE_ID=
NEXT_PUBLIC_ODOO_BASE_URL=https://odoo.logos.co
NEXT_PUBLIC_ODOO_MAILING_LIST_ID=2
NEXT_PUBLIC_ODOO_MAILING_LIST_ID=2

View File

@ -43,7 +43,10 @@ const PodcastShowPage = ({
export const getStaticProps = async ({ params }: GetStaticPropsContext) => {
// TODO : error handling
const { data: podcastShows, errors: podcastShowsErrors } =
await unbodyApi.getPodcastShows({ populateEpisodes: false })
await unbodyApi.getPodcastShows({
populateEpisodes: true,
episodesLimit: 6,
})
// TODO : error handling
const { data: highlightedEpisodes, errors: highlightedEpisodesErrors } =
@ -62,11 +65,20 @@ export const getStaticProps = async ({ params }: GetStaticPropsContext) => {
}
}
const latestEps = podcastShows
.flatMap((show) => show.episodes)
.sort((a, b) => {
const aDate = new Date(a!.publishedAt)
const bDate = new Date(b!.publishedAt)
return aDate > bDate ? -1 : 1
})
.filter((p) => p?.highlighted !== true)
return {
props: {
shows: podcastShows,
highlightedEpisodes,
latestEpisodes: latestEpisodes.map((ep) => ({ ...ep, show: null })),
latestEpisodes: latestEps,
// errors,
},
revalidate: 10,

View File

@ -73,7 +73,7 @@ const getRecordDate = (record: PageRecord) =>
? new Date(record.publishedAt)
: new Date(record.modifiedAt!)
const sortPosts = (a: LPE.Post.Document, b: LPE.Post.Document) =>
export const sortPosts = (a: LPE.Post.Document, b: LPE.Post.Document) =>
getRecordDate(a) > getRecordDate(b) ? -1 : 1
type PageRecord = LPE.Post.Document | LPE.StaticPage.Document
@ -228,7 +228,7 @@ export class UnbodyService {
else newData.draftStaticPages.push(staticPage)
}
newData.posts = [...newData.articles, ...newData.episodes]
newData.posts = [...newData.articles, ...newData.episodes].sort(sortPosts)
newData.allRecords = [...articles, ...episodes, ...staticPages]
const oldData = { ...this.data }