Skip to content

Commit ad50008

Browse files
google-labs-jules[bot]srod
authored andcommitted
feat(docs): add pagination to documentation pages
- Created `Pagination` component to generate Previous/Next links based on sidebar structure. - Integrated `Pagination` into `MainLayout` to appear at the bottom of content pages. - Added accessibility features (aria-labels, focus outlines, semantic HTML). - Styled with existing design system variables.
1 parent 0a221f8 commit ad50008

File tree

2 files changed

+142
-0
lines changed

2 files changed

+142
-0
lines changed
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
---
2+
import { SIDEBAR } from "../consts";
3+
4+
type Props = {
5+
currentPage: string;
6+
};
7+
8+
const { currentPage } = Astro.props;
9+
// Remove trailing slash if present, and remove leading slash
10+
const cleanPath = currentPage.replace(/\/$/, "").replace(/^\//, "");
11+
12+
const sidebar = SIDEBAR;
13+
const allLinks = Object.values(sidebar).flat();
14+
const index = allLinks.findIndex((x) => x.link === cleanPath);
15+
16+
const prev = allLinks[index - 1];
17+
const next = allLinks[index + 1];
18+
---
19+
20+
<nav class="pagination" aria-label="Pagination">
21+
{
22+
prev ? (
23+
<a
24+
class="link-button prev"
25+
href={`${import.meta.env.BASE_URL}${prev.link}`}
26+
rel="prev"
27+
>
28+
<svg
29+
xmlns="http://www.w3.org/2000/svg"
30+
viewBox="0 0 24 24"
31+
fill="currentColor"
32+
width="24"
33+
height="24"
34+
aria-hidden="true"
35+
>
36+
<path d="M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z" />
37+
</svg>
38+
<div class="text-wrapper">
39+
<span class="label">Previous</span>
40+
<span class="title">{prev.text}</span>
41+
</div>
42+
</a>
43+
) : (
44+
<span />
45+
)
46+
}
47+
48+
{
49+
next && (
50+
<a
51+
class="link-button next"
52+
href={`${import.meta.env.BASE_URL}${next.link}`}
53+
rel="next"
54+
>
55+
<div class="text-wrapper">
56+
<span class="label">Next</span>
57+
<span class="title">{next.text}</span>
58+
</div>
59+
<svg
60+
xmlns="http://www.w3.org/2000/svg"
61+
viewBox="0 0 24 24"
62+
fill="currentColor"
63+
width="24"
64+
height="24"
65+
aria-hidden="true"
66+
>
67+
<path d="M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z" />
68+
</svg>
69+
</a>
70+
)
71+
}
72+
</nav>
73+
74+
<style>
75+
.pagination {
76+
display: flex;
77+
justify-content: space-between;
78+
margin-top: 4rem;
79+
padding-top: 2rem;
80+
border-top: 1px solid var(--theme-divider);
81+
gap: 1rem;
82+
}
83+
84+
.link-button {
85+
display: flex;
86+
align-items: center;
87+
text-decoration: none;
88+
color: var(--theme-text);
89+
padding: 0.75rem 1rem;
90+
border-radius: 0.5rem;
91+
border: 1px solid var(--theme-divider);
92+
transition:
93+
border-color 0.2s,
94+
background-color 0.2s;
95+
max-width: 48%;
96+
gap: 0.5rem;
97+
flex: 1;
98+
}
99+
100+
.link-button:hover,
101+
.link-button:focus-visible {
102+
border-color: var(--theme-text-accent);
103+
background-color: var(--theme-bg-hover);
104+
outline: none;
105+
}
106+
107+
.link-button:focus-visible {
108+
outline: 2px solid var(--theme-text-accent);
109+
outline-offset: 2px;
110+
}
111+
112+
.link-button.next {
113+
justify-content: flex-end;
114+
text-align: right;
115+
}
116+
117+
.text-wrapper {
118+
display: flex;
119+
flex-direction: column;
120+
}
121+
122+
.label {
123+
font-size: 0.75rem;
124+
opacity: 0.7;
125+
margin-bottom: 0.1rem;
126+
text-transform: uppercase;
127+
letter-spacing: 0.05em;
128+
}
129+
130+
.title {
131+
font-weight: 600;
132+
font-size: 1rem;
133+
line-height: 1.2;
134+
}
135+
136+
/* Ensure icons don't shrink */
137+
svg {
138+
flex-shrink: 0;
139+
}
140+
</style>

docs/src/layouts/MainLayout.astro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Header from "../components/Header/Header.astro";
77
import HeadSEO from "../components/HeadSEO.astro";
88
import LeftSidebar from "../components/LeftSidebar/LeftSidebar.astro";
99
import PageContent from "../components/PageContent/PageContent.astro";
10+
import Pagination from "../components/Pagination.astro";
1011
// import RightSidebar from '../components/RightSidebar/RightSidebar.astro';
1112
import { SITE } from "../consts";
1213
@@ -124,6 +125,7 @@ const currentPage = Astro.url.pathname;
124125
<div id="grid-main">
125126
<PageContent title={data.title} headings={headings}>
126127
<slot />
128+
<Pagination currentPage={currentPage} />
127129
</PageContent>
128130
</div>
129131
<!-- <aside id="grid-right" class="grid-sidebar" title="Table of Contents">

0 commit comments

Comments
 (0)