@@ -3,6 +3,7 @@ import type { MarkdownInstance } from "astro";
33import Navlink from " ./Navlink.astro" ;
44import NavDropdown from " ./NavDropdown.astro" ;
55import " ./Navigation.css" ;
6+ import { type CollectionEntry , getCollection } from " astro:content" ;
67
78interface Frontmatter {
89 title: string ;
@@ -11,31 +12,20 @@ interface Frontmatter {
1112 startDate: Date ;
1213 finishDate? : Date ;
1314}
14- const matches = import .meta .glob <MarkdownInstance <Frontmatter >>(
15- " ../pages/projects/*.{md,mdx}" ,
16- { eager: true },
17- );
18- const allProjects = Object .values (matches ).sort ((a , b ) => {
15+
16+ const projects = await getCollection (" projects" );
17+ const sortedProjects = projects .sort ((a , b ) => {
1918 // If one activity is ongoing, and the other isn't, then onging activity is first
20- if (! a .frontmatter .finishDate && b .frontmatter .finishDate ) {
19+ if (! a .data .finishDate && b .data .finishDate ) {
2120 return - 1 ;
2221 }
23- if (b . frontmatter .finishDate && ! b .frontmatter .finishDate ) {
22+ if (a . data .finishDate && ! b .data .finishDate ) {
2423 return 1 ;
2524 }
2625
27- // If both are finished, sort by that first
28- if (a .frontmatter .finishDate && b .frontmatter .finishDate ) {
29- const result = new Date (b .frontmatter .finishDate ).getTime () - new Date (a .frontmatter .finishDate ).getTime ();
30- if (result != 0 ) {
31- return result ;
32- }
33- }
3426 // Then sort by start date
35- return new Date ( b . frontmatter .startDate ) .getTime () - new Date ( a . frontmatter .startDate ) .getTime ();
27+ return b . data .startDate .getTime () - a . data .startDate .getTime ();
3628});
37-
38- const size = allProjects .length ;
3929---
4030
4131<script is:inline >
@@ -63,8 +53,8 @@ const size = allProjects.length;
6353 <NavDropdown title =" Technical Projects" >
6454 <a href =" /projects" >All Projects</a >
6555 {
66- allProjects .map ((project ) => (
67- <a href = { project .url } >{ project .frontmatter .title } </a >
56+ projects .map ((project ) => (
57+ <a href = { project .id } >{ project .data .title } </a >
6858 ))
6959 }
7060 </NavDropdown >
0 commit comments