import Page from 'site/components/wrappers/page.js' import useApp from 'site/hooks/useApp.js' import TimeAgo from 'react-timeago' import MdxWrapper from 'shared/components/wrappers/mdx' import mdxCompiler from 'shared/mdx/compiler' import Markdown from 'react-markdown' import Head from 'next/head' import PageLink from 'shared/components/page-link.js' import Lightbox from 'shared/components/lightbox.js' import { serverSideTranslations } from 'next-i18next/serverSideTranslations' import { strapiHost } from 'shared/config/freesewing.mjs' import { strapiImage } from 'shared/utils.js' import { useTranslation } from 'next-i18next' const strapi = "https://posts.freesewing.org" const Maker = ({ maker }) => { const { t } = useTranslation(['posts']) return (
{maker?.displayname}

) } const PostPage = ({ post, maker }) => { const app = useApp() const crumbs = [ app.getBreadcrumb('showcase'), [ post.title ] ] return (
[{post.date}]
{post.designs.map(design => ( ))}
By {maker.displayname || 'FIXME: No displayname'}
{post.caption}
) } /* * getStaticProps() is used to fetch data at build-time. * * On this page, it is loading the showcase content from strapi. * * This, in combination with getStaticPaths() below means this * page will be used to render/generate all showcase content. * * To learn more, see: https://nextjs.org/docs/basic-features/data-fetching */ export async function getStaticProps({ params, locale }) { const { slug } = params const post = await fetch( `${strapiHost}/showcaseposts?_locale=${locale}&slug_eq=${slug}` ) .then(response => response.json()) .then(data => data[0]) .catch(err => console.log(err)) const designs = [post.design1] if (post.design2 && post.design2.length > 2) designs.push(post.design2) if (post.design3 && post.design3.length > 2) designs.push(post.design3) return { props: { post: { slug, ...(await mdxCompiler(post.body)), title: post.title, date: post.date, caption: post.caption, image: { w: post.image.width, h: post.image.height, url: post.image.url }, designs, }, maker: { displayname: post.maker.displayname, slug: post.maker.slug, image: strapiImage(post.maker.picture, ['small']), ...(await mdxCompiler(post.maker.about)), }, ...(await serverSideTranslations(locale)), } } } export const getStaticPaths = async () => { const paths = await fetch( `${strapiHost}/showcaseposts?_locale=en&_limit=-1` ) .then(response => response.json()) .then(data => data.map(post => ({ params: { slug: post.slug } }))) .catch(err => console.log(err)) return { paths, fallback: false, } } export default PostPage