Skip to content

Commit

Permalink
sort blog bottom nav by date
Browse files Browse the repository at this point in the history
  • Loading branch information
amozoss committed Jul 8, 2024
1 parent 4e75003 commit de9570e
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/markdoc/navigation.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ function getFrontmatter(filepath) {
redirects: frontmatter.redirects,
docId: frontmatter.docId,
weight: frontmatter.weight,
date: frontmatter.date,
}
}

Expand Down Expand Up @@ -161,6 +162,16 @@ function sortByWeightThenTitle(arr) {
})
}

function sortByDateThenTitle(arr) {
arr.sort((a, b) => {
if (a.date !== b.date) {
return new Date(b.date) - new Date(a.date)
} else {
return a.title.localeCompare(b.title)
}
})
}

export default function (nextConfig = {}) {
let cache = new Map()

Expand All @@ -184,7 +195,7 @@ export default function (nextConfig = {}) {
let blog = walkDir(`${dir}/\(blog\)/blog`, 'blog', {
hasRoot: false,
})
sortByWeightThenTitle(blog)
sortByDateThenTitle(blog)

let getRedirects = (space) => {
let re = extractRedirects(space)
Expand Down

0 comments on commit de9570e

Please sign in to comment.