Replies: 1 comment 3 replies
-
👋 I'm assuming we are talking in the case of a page using the In this case, there is no built-in option to use the title only in the pagination links but keep the label in the sidebar. However, this is something achievable using component overrides which allow you to replace and customize the default components used by Starlight. An override for the ---
// src/components/Pagination.astro
import type { Props } from '@astrojs/starlight/props';
import Default from '@astrojs/starlight/components/Pagination.astro';
import { getEntry } from 'astro:content';
const { pagination } = Astro.props;
async function updatePaginationLink(link: Props['pagination']['next']) {
if (!link) return link;
if (!link.href.startsWith('/')) return link;
// Get the slug of the prev/next page.
const slug = link.href.replace(/^\//, '').replace(/(\/|\.html)$/, '');
// Get the associated content collection entry.
const entry = await getEntry('docs', slug ? slug : 'index');
if (!entry) return link;
// Update the label of the link with the title of the entry if it exists.
return { ...link, label: entry.data.title };
}
---
<Default
{...Astro.props}
pagination={{
prev: await updatePaginationLink(pagination.prev),
next: await updatePaginationLink(pagination.next),
}}><slot /></Default
> You can find a working version of this override in this basic example I have setup on StackBlitz. |
Beta Was this translation helpful? Give feedback.
-
is there any method to show next and previous page title in pagination component instead of label ?
Beta Was this translation helpful? Give feedback.
All reactions