Skip to content

Commit

Permalink
notes: parse modified time before using it for sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
ooloth committed Dec 23, 2024
1 parent 931f005 commit 2cc2b26
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/pages/notes.astro
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,16 @@ import { getDrafts } from '../utils/posts'
const bookmarks = await getBookmarks()
const notes = await getNotes()
const tags = await getAllTagsInNotes()
const drafts = await getDrafts()
const tags = await getAllTagsInNotes()
const notesByLastModified = [...bookmarks, ...notes, ...drafts].sort((a, b) => {
if (a.data.lastModified < b.data.lastModified) {
return 1
}
if (a.data.lastModified > b.data.lastModified) {
return -1
}
return 0
const aTime = new Date(a.data.lastModified).getTime()
const bTime = new Date(b.data.lastModified).getTime()
return bTime - aTime
})
const getEmoji = (item: Bookmark | Draft | Writing): string => {
const getLinkEmoji = (item: Bookmark | Draft | Writing): string => {
if (item.data.favicon) {
return `<img src="${item.data.favicon}" alt="" width="20" class="inline-block -mt-1 mr-[0.15rem] ml-[0.2rem]" />`
}
Expand Down Expand Up @@ -71,7 +66,7 @@ const getEmoji = (item: Bookmark | Draft | Writing): string => {
notesByLastModified.map((item, index) => (
<li class="inline">
<span class="whitespace-nowrap">
<span class="inline mr-1" set:html={getEmoji(item)} />
<span class="inline mr-1" set:html={getLinkEmoji(item)} />
<a href={`/${item.slug}/`} class="inline link-nav whitespace-normal">
{item.data.title || item.slug} {item.data.author ? ` (${item.data.author})` : ''}
</a>
Expand Down

0 comments on commit 2cc2b26

Please sign in to comment.