Skip to content
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 3 commits into from
Jan 22, 2025
Merged

fix: date ordering in explorer folders #90

merged 3 commits into from
Jan 22, 2025

Conversation

vintrocode
Copy link

No description provided.

Copy link

cloudflare-workers-and-pages bot commented Jan 21, 2025

Deploying blog with  Cloudflare Pages  Cloudflare Pages

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

View logs

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",
})
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is never used

@VVoruganti VVoruganti merged commit 6aa1314 into v4 Jan 22, 2025
3 checks passed
@VVoruganti VVoruganti deleted the fix-explorer branch January 22, 2025 22:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants