@@ -4,23 +4,42 @@ import Layout from "@layouts/Layout.astro";
44import Drawer from " @layouts/Drawer.astro" ;
55
66import Tags from " @components/Tags.astro" ;
7+ import { ArrowLeft , ArrowRight } from " lucide-astro" ;
8+
9+ function slugOf(idea : any ) {
10+ let slug = idea .filePath
11+ slug = slug ?.replace (/ ^ idea\/ / , " " );
12+ slug = slug ?.replace (/ \. mdx? $ / , " " );
13+ return slug ;
14+ }
715
816export async function getStaticPaths() {
9- const ideas = await getCollection (" ideas" );
17+ const ideas = (await getCollection (" ideas" ))
18+ .filter (idea => idea .data .pubDate )
19+ .sort ((a , b ) => a .data .pubDate ! .valueOf () - b .data .pubDate ! .valueOf ())
1020
1121 return ideas .map (idea => {
12- let slug = idea .filePath
13- slug = slug ?.replace (/ ^ idea\/ / , " " );
14- slug = slug ?.replace (/ \. mdx? $ / , " " );
22+ function slugOf(idea : any ) {
23+ let slug = idea .filePath
24+ slug = slug ?.replace (/ ^ idea\/ / , " " );
25+ slug = slug ?.replace (/ \. mdx? $ / , " " );
26+ return slug ;
27+ }
28+
29+ const i = ideas .findIndex (each => slugOf (each ) === slugOf (idea ))
30+ const prev = i > 0 ? ideas [i - 1 ] : undefined
31+ const next = i < ideas .length - 1 ? ideas [i + 1 ] : undefined
32+ const slug = slugOf (idea )
33+
1534 return {
16- params: { slug },
17- props : { idea },
35+ params: { slug },
36+ props : { idea , prev , next },
1837 }
1938 });
2039}
2140
22- const { idea } = Astro .props ;
23- const { Content } = await render (idea );
41+ const { idea, prev, next } = Astro .props ;
42+ const { Content } = await render (idea );
2443---
2544
2645<Layout >
@@ -53,5 +72,40 @@ const { Content } = await render(idea);
5372 <Content />
5473 </div >
5574 </div >
75+
76+ <!-- Footer -->
77+ <div class =" flex flex-col w-full items-center" >
78+ <!-- Spacing -->
79+ <div class =" h-4" ></div >
80+
81+ <div class =" flex flex-row w-3xs sm:w-2xl justify-center gap-2" >
82+ { prev && (
83+ <a href = { ` /idea/${slugOf (prev )} ` } class = " flex flex-row flex-1 items-center rounded-lg hover:bg-base-200" >
84+ <ArrowLeft class = " w-10 h-10" />
85+ <div class = " divider divider-horizontal" ></div >
86+ <div class = " flex flex-col flex-1 items-start" >
87+ <span class = " text-lg sm:text-xl font-bold" >
88+ { prev .data .title }
89+ </span >
90+ </div >
91+ </a >
92+ )}
93+
94+ { next && (
95+ <a href = { ` /idea/${slugOf (next )} ` } class = " flex flex-row flex-1 items-center rounded-lg hover:bg-base-200" >
96+ <div class = " flex flex-col flex-1 items-end" >
97+ <span class = " text-lg sm:text-xl font-bold" >
98+ { next .data .title }
99+ </span >
100+ </div >
101+ <div class = " divider divider-horizontal" ></div >
102+ <ArrowRight class = " w-10 h-10" />
103+ </a >
104+ )}
105+ </div >
106+
107+ <!-- Spacing -->
108+ <div class =" h-4" ></div >
109+ </div >
56110 </Drawer >
57111</Layout >
0 commit comments