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

Function getBlogCategory

apps/site/layouts/Blog.tsx:15–37  ·  view source on GitHub ↗
(pathname: string)

Source from the content-addressed store, hash-verified

13import styles from './layouts.module.css';
14
15const getBlogCategory = (pathname: string) => {
16 // pathname format can either be: /en/blog/{category}
17 // or /en/blog/{category}/page/{page}
18 // hence we attempt to interpolate the full /en/blog/{category}/page/{page}
19 // and in case of course no page argument is provided we define it to 1
20 // note that malformed routes can't happen as they are all statically generated
21 const [, , category = 'all', , page = 1] = pathname.split('/') as [
22 unknown,
23 unknown,
24 BlogCategory,
25 unknown,
26 number,
27 ];
28
29 const { posts, pagination } = getBlogData(category, Number(page));
30
31 return {
32 category,
33 posts,
34 pagination,
35 page: Number(page),
36 };
37};
38
39const BlogLayout: FC = () => {
40 const t = useTranslations();

Callers 1

BlogLayoutFunction · 0.85

Calls 1

getBlogDataFunction · 0.90

Tested by

no test coverage detected