// Dependencies import { serverSideTranslations } from 'next-i18next/serverSideTranslations' import { sanitySiteImage, numPerPage, sanityLoader } from 'site/components/sanity/utils.mjs' // Hooks import { useTranslation } from 'next-i18next' // Components import Link from 'next/link' import { TimeAgo } from 'shared/components/wrappers/mdx.mjs' import { PageWrapper, ns as pageNs } from 'shared/components/wrappers/page.mjs' import { Pagination } from 'shared/components/navigation/pagination.mjs' import { siteConfig } from 'site/site.config.mjs' // Translation namespaces used on this page const namespaces = [...new Set(['designs', ...pageNs])] const textShadow = { style: { textShadow: '1px 1px 1px #000000, -1px -1px 1px #000000, 1px -1px 1px #000000, -1px 1px 1px #000000, 2px 2px 1px #000000', }, } const Preview = ({ post, t }) => (
{post.title}
) /* * Each page MUST be wrapped in the PageWrapper component. * You also MUST spread props.page into this wrapper component * when path and locale come from static props (as here) * or set them manually. */ const BlogIndexPage = ({ posts, page, current, total }) => { const { t } = useTranslation() return (
{posts.map((post) => ( ))}
) } export default BlogIndexPage export async function getStaticProps({ locale, params }) { const allPosts = await sanityLoader({ language: locale, type: 'blog', order: 'date desc', filters: '{_id, date, slug, title, author, image}', }) const pageNum = parseInt(params.page) return { props: { posts: allPosts.slice(numPerPage * (pageNum - 1), numPerPage * pageNum), current: pageNum, total: allPosts.length, ...(await serverSideTranslations(locale, namespaces)), page: { locale, // title: 'Freesewing Blog', path: ['blog', 'page', params.page], }, }, } } export const getStaticPaths = async () => { const numPosts = await sanityLoader({ query: `count(*[_type == "blogen"])` }) const numPages = Math.ceil(numPosts / numPerPage) const paths = [] for (let i = 0; i < numPages; i++) { const pathName = `/blog/page/${i + 1}` siteConfig.languages.forEach((l) => paths.push(`${l.length ? '/' : ''}${l}${pathName}`)) } return { paths, fallback: false, } }