Skip to content

Commit 3e1aeb6

Browse files
committed
prev / next entry arrow links wip
1 parent 24829dc commit 3e1aeb6

3 files changed

Lines changed: 37 additions & 0 deletions

File tree

src/icons/arrow-left.svg

Lines changed: 3 additions & 0 deletions
Loading

src/icons/arrow-right.svg

Lines changed: 3 additions & 0 deletions
Loading

src/pages/work/[...slug].astro

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,43 @@ type Props = CollectionEntry<'work'>;
2222
const entry = Astro.props;
2323
const { title, description, pubDate, tags } = entry.data;
2424
const { Content } = await render(entry);
25+
26+
// Get all entries in current category for prev/next arrow navigation
27+
const projects = (await getCollection('work'))
28+
.filter((project) => project.data.category === entry.data.category)
29+
.sort((a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf());
30+
31+
const currentIndex = projects.findIndex((item) => item.id === entry.id);
32+
const prevEntry = projects[currentIndex - 1];
33+
const nextEntry = projects[currentIndex + 1];
2534
---
2635

2736
<BaseLayout {...entry.data}>
2837
<div class="grid-cols-12 lg:grid">
2938
<div class="col-span-3">
3039
<div class="sticky top-12">
40+
<!-- Previous / Next arrows -->
41+
<div class="mb-6 flex gap-4">
42+
{
43+
prevEntry && (
44+
<a
45+
href={`/work/${prevEntry.id}`}
46+
aria-label="Previous"
47+
class="px-3 py-2 dark:text-white"
48+
>
49+
<Icon name="arrow-left" size={20} />
50+
</a>
51+
)
52+
}
53+
{
54+
nextEntry && (
55+
<a href={`/work/${nextEntry.id}`} aria-label="Next" class="px-3 py-2 dark:text-white">
56+
<Icon name="arrow-right" size={20} />
57+
</a>
58+
)
59+
}
60+
</div>
61+
3162
<h1 class="mb-1 text-4xl font-medium dark:text-white">{title}</h1>
3263
<p class="opacity-60">
3364
<FormattedDate date={pubDate} />

0 commit comments

Comments
 (0)