import type { FC } from 'react'; import { getClientContext } from '@/client-context'; import CrossLink from '@/components/Common/CrossLink'; import getBlogData from '@/next-data/blogData'; const WithBlogCrossLinks: FC = async () => { const { pathname } = getClientContext(); // Extracts from the static URL the components used for the Blog Post slug const [, , category, postname] = pathname.split('/'); const { posts } = await getBlogData(category); const currentItem = posts.findIndex( ({ slug }) => slug === `/blog/${category}/${postname}` ); const [previousCrossLink, nextCrossLink] = [ posts[currentItem - 1], posts[currentItem + 1], ]; return (
{(previousCrossLink && ( )) ||
} {nextCrossLink && ( )}
); }; export default WithBlogCrossLinks;