22import { getCollection , render } from " astro:content" ;
33import Layout from " @layouts/Layout.astro" ;
44import Drawer from " @layouts/Drawer.astro" ;
5+ import { Idea } from " @tool/idea" ;
56
67import 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- }
8+ import { ArrowLeft , ArrowRight , Ellipsis } from " lucide-astro" ;
159
1610export async function getStaticPaths() {
1711 const ideas = (await getCollection (" ideas" ))
1812 .filter (idea => idea .data .pubDate )
19- .sort ((a , b ) => a .data .pubDate ! .valueOf () - b .data .pubDate ! .valueOf ())
20-
21- return ideas .map (idea => {
22- function slugOf(idea : any ) {
23- let slug = idea .filePath
24- slug = slug ?.replace (/ ^ idea\/ / , " " );
25- slug = slug ?.replace (/ \. mdx? $ / , " " );
26- return slug ;
27- }
13+ .sort ((a , b ) => (
14+ a .data .pubDate ! .valueOf () -
15+ b .data .pubDate ! .valueOf ()
16+ ))
2817
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 )
18+ return ideas .map (idea => {
19+ const
20+ where = ideas .findIndex (each => Idea .slug (each ) === Idea .slug (idea )),
21+ prevIdea = ideas [(where + ideas .length - 1 ) % ideas .length ],
22+ nextIdea = ideas [(where + ideas .length + 1 ) % ideas .length ],
23+ slug = Idea .slug (idea );
3324
3425 return {
35- params: { slug },
36- props : { idea , prev , next },
26+ params: { slug },
27+ props : { idea , prevIdea , nextIdea },
3728 }
3829 });
3930}
4031
41- const { idea, prev, next } = Astro .props ;
42- const { Content } = await render (idea );
32+ const { idea, prevIdea, nextIdea } = Astro .props ;
33+ const { Content } = await render (idea );
4334---
4435
4536<Layout >
@@ -68,7 +59,7 @@ const { Content } = await render(idea);
6859 </div >
6960
7061 <!-- Article -->
71- <div class =" flex flex-col w-full flex-1 sm:max-w-2xl sm:shadow-lg prose prose-sm sm:prose-lg break-words sm:break-normal p-8" >
62+ <div class =" flex flex-col w-full flex-1 sm:max-w-2xl sm:shadow-lg prose prose-sm sm:prose-lg break-words sm:break-normal p-4 sm:p- 8" >
7263 <Content />
7364 </div >
7465 </div >
@@ -78,34 +69,36 @@ const { Content } = await render(idea);
7869 <!-- Spacing -->
7970 <div class =" h-4" ></div >
8071
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" />
72+ <div class =" flex flex-row w-fit sm:w-2xl justify-center items-center gap-2" >
73+
74+ <a href ={ ` /idea/${Idea .slug (prevIdea )} ` } class =" flex flex-row flex-1 p-2 self-stretch items-center justify-center rounded-lg hover:bg-base-200" >
75+ <ArrowLeft class =" w-10 h-10" />
76+ <div class =" hidden sm:flex divider divider-horizontal" ></div >
77+ <span class =" hidden sm:inline text-lg font-bold flex-1 text-center" >
78+ { prevIdea .data .title }
79+ </span >
80+ </a >
81+
82+ <span class =" tooltip tooltip-bottom" data-tip =" More Ideas" >
83+ <a href =" /idea" class =" btn btn-xl btn-ghost btn-circle" >
84+ <Ellipsis class =" w-10 h-10" />
10385 </a >
104- )}
86+ </span >
87+
88+
89+ <a href ={ ` /idea/${Idea .slug (nextIdea )} ` } class =" flex flex-row flex-1 p-2 self-stretch items-center justify-center rounded-lg hover:bg-base-200" >
90+ <span class =" hidden sm:inline text-lg font-bold flex-1 text-center" >
91+ { nextIdea .data .title }
92+ </span >
93+ <div class =" hidden sm:flex divider divider-horizontal" ></div >
94+ <ArrowRight class =" w-10 h-10" />
95+ </a >
96+
97+
10598 </div >
10699
107100 <!-- Spacing -->
108- <div class =" h-4 " ></div >
101+ <div class =" h-12 " ></div >
109102 </div >
110103 </Drawer >
111104</Layout >
0 commit comments