(pathname: string)
| 13 | import styles from './layouts.module.css'; |
| 14 | |
| 15 | const 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 | |
| 39 | const BlogLayout: FC = () => { |
| 40 | const t = useTranslations(); |
no test coverage detected