Skip to content

Commit ff6b324

Browse files
committed
Make sure things are sorted
1 parent 411e7f5 commit ff6b324

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

app/src/routes/essays/+page.server.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,15 @@ export async function load() {
1010
// Filter for markdown files (exclude _.md)
1111
const essayFiles = files
1212
.filter((file: string) => file.endsWith('.md') && file !== '_.md')
13-
.sort((a: string, b: string) => b.localeCompare(a)); // Sort in reverse chronological order
13+
.sort((a: string, b: string) => {
14+
const dateValue = (name: string) => {
15+
const head = name.split('_')[0] ?? '';
16+
const [y, m] = head.split('-').map(Number);
17+
// default to 0 if missing to keep non-conforming names at the end
18+
return new Date(y || 0, (m ? m - 1 : 0), 1).getTime();
19+
};
20+
return dateValue(b) - dateValue(a); // newest first
21+
});
1422

1523
// Extract metadata from filenames
1624
const essays = essayFiles.map((file: string) => {

app/static/writing/essays/_.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
Next essay:
7-
- Fancy Rug effect (IP)
7+
- What's the best amount of money? (A: enough)
88
- Walking is a superpower
99
- Civil discourse and complete thoughts
1010

0 commit comments

Comments
 (0)