MCPcopy Create free account
hub / github.com/nodejs/nodejs.org / WithBlogCrossLinks

Function WithBlogCrossLinks

apps/site/components/withBlogCrossLinks.tsx:8–49  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

6import type { FC } from 'react';
7
8const WithBlogCrossLinks: FC = () => {
9 const { pathname } = getClientContext();
10
11 // Extracts from the static URL the components used for the Blog Post slug
12 const [, , category, postname] = pathname.split('/') as [
13 unknown,
14 unknown,
15 BlogCategory,
16 string,
17 ];
18
19 const { posts } = getBlogData(category);
20
21 const currentItem = posts.findIndex(
22 ({ slug }) => slug === `/blog/${category}/${postname}`
23 );
24
25 const [previousCrossLink, nextCrossLink] = [
26 posts[currentItem - 1],
27 posts[currentItem + 1],
28 ];
29
30 return (
31 <div className="max-ml:grid-cols-1 mt-4 grid w-full grid-cols-2 gap-4">
32 {(previousCrossLink && (
33 <CrossLink
34 type="previous"
35 text={previousCrossLink.title}
36 link={previousCrossLink.slug}
37 />
38 )) || <div />}
39
40 {nextCrossLink && (
41 <CrossLink
42 type="next"
43 text={nextCrossLink.title}
44 link={nextCrossLink.slug}
45 />
46 )}
47 </div>
48 );
49};
50
51export default WithBlogCrossLinks;

Callers

nothing calls this directly

Calls 1

getBlogDataFunction · 0.90

Tested by

no test coverage detected