forked from jackyzha0/quartz
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: date ordering in explorer folders #90
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Deploying blog with
|
Latest commit: |
3f35462
|
Status: | ✅ Deploy successful! |
Preview URL: | https://2680c19b.plastic-labs-github-io.pages.dev |
Branch Preview URL: | https://fix-explorer.plastic-labs-github-io.pages.dev |
VVoruganti
reviewed
Jan 21, 2025
quartz.layout.ts
Outdated
Comment on lines
6
to
37
// Create a date-based sort function for the explorer | ||
const explorerSortDateFirst = (a: FileNode, b: FileNode) => { | ||
// Always keep folders before files | ||
if (a.file && !b.file) return 1 | ||
if (!a.file && b.file) return -1 | ||
|
||
// If both are files or both are folders | ||
if (a.file?.frontmatter?.date && b.file?.frontmatter?.date) { | ||
const parseDate = (dateStr: string) => { | ||
const [month, day, year] = dateStr.split('.') | ||
// Assuming YY format, convert to full year | ||
const fullYear = year.length === 2 ? 2000 + parseInt(year) : parseInt(year) | ||
return new Date(fullYear, parseInt(month) - 1, parseInt(day)) | ||
} | ||
|
||
const aDate = parseDate(a.file.frontmatter.date as string) | ||
const bDate = parseDate(b.file.frontmatter.date as string) | ||
|
||
// Sort descending (newest first) | ||
return bDate.getTime() - aDate.getTime() | ||
} | ||
|
||
// If only one has a date, prioritize it | ||
if (a.file?.frontmatter?.date) return -1 | ||
if (b.file?.frontmatter?.date) return 1 | ||
|
||
// Fall back to alphabetical sorting | ||
return a.displayName.localeCompare(b.displayName, undefined, { | ||
numeric: true, | ||
sensitivity: "base", | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is never used
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.