Skip to content

Commit 763651e

Browse files
committed
index: sort projcts
1 parent 09a7d5b commit 763651e

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/pages/index.astro

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,19 @@ import Hero from "../images/hero.jpg";
1515
import LabCafe from "../images/lab-cafe.jpg";
1616
import LogoGMOMedia from "../images/logo-gmo-media.png";
1717
18-
const projects = (await getCollection("projects")).slice(0, 6);
19-
const articles = (await getCollection("articles")).slice(0, 6);
18+
const projects = (await getCollection("projects"))
19+
.sort((a, b) => {
20+
const a_order = a.data.order ?? Number.POSITIVE_INFINITY,
21+
b_order = b.data.order ?? Number.POSITIVE_INFINITY;
22+
if (a_order !== b_order) {
23+
return a_order - b_order;
24+
}
25+
return b.data.date.getTime() - a.data.date.getTime();
26+
})
27+
.slice(0, 6);
28+
const articles = (await getCollection("articles"))
29+
.sort((a, b) => b.data.date.getTime() - a.data.date.getTime())
30+
.slice(0, 6);
2031
---
2132

2233
<GlobalLayout title={null} description={null} focus={Focus.none}>

0 commit comments

Comments
 (0)