2022-05-30 16:40:51 +02:00
|
|
|
import Page from 'site/components/wrappers/page.js'
|
2022-01-02 17:16:15 +01:00
|
|
|
import useApp from 'site/hooks/useApp.js'
|
|
|
|
import Link from 'next/link'
|
|
|
|
import TimeAgo from 'react-timeago'
|
2022-05-29 18:44:32 +02:00
|
|
|
import { strapiHost } from 'shared/config/freesewing.mjs'
|
2022-06-17 12:02:09 +02:00
|
|
|
import { strapiImage } from 'shared/utils'
|
2022-05-29 18:44:32 +02:00
|
|
|
import { useTranslation } from 'next-i18next'
|
|
|
|
import { serverSideTranslations } from 'next-i18next/serverSideTranslations'
|
2022-01-02 17:16:15 +01:00
|
|
|
|
|
|
|
const strapi = "https://posts.freesewing.org"
|
2022-06-09 13:55:11 +02:00
|
|
|
const textShadow = {
|
|
|
|
style: {
|
|
|
|
textShadow: "1px 1px 1px #000000, -1px -1px 1px #000000, 1px -1px 1px #000000, -1px 1px 1px #000000, 2px 2px 1px #000000"
|
|
|
|
}
|
|
|
|
}
|
2022-01-02 17:16:15 +01:00
|
|
|
|
|
|
|
const Preview = ({ app, post }) => (
|
2022-05-29 18:44:32 +02:00
|
|
|
<div className="shadow rounded-lg">
|
2022-01-02 17:16:15 +01:00
|
|
|
<Link href={`/blog/${post.slug}`}>
|
|
|
|
<a title={post.title} className="hover:underline">
|
2022-05-29 18:44:32 +02:00
|
|
|
<div className="bg-base-100 w-full aspect-video shadow flex flex-column items-end rounded-lg" style={{
|
|
|
|
backgroundImage: `url(${strapi}${post.image.sizes.medium.url})`,
|
2022-01-02 17:16:15 +01:00
|
|
|
backgroundSize: 'cover',
|
|
|
|
}}>
|
|
|
|
<div className="grow"></div>
|
2022-05-30 16:40:51 +02:00
|
|
|
<div className="text-right mb-3 lg:mb-8">
|
2022-01-02 17:16:15 +01:00
|
|
|
<div className={`
|
2022-06-09 13:55:11 +02:00
|
|
|
bg-neutral text-neutral-content bg-opacity-40 text-right
|
2022-05-30 16:40:51 +02:00
|
|
|
px-4 py-1
|
|
|
|
lg:px-8 lg:py-4
|
|
|
|
|
2022-01-02 17:16:15 +01:00
|
|
|
`}>
|
|
|
|
<h5 className={`
|
|
|
|
text-neutral-content
|
2022-06-09 13:55:11 +02:00
|
|
|
text-xl font-bold
|
|
|
|
md:text-2xl md:font-normal
|
2022-05-29 18:44:32 +02:00
|
|
|
xl:text-3xl
|
2022-06-09 13:55:11 +02:00
|
|
|
`} {...textShadow}
|
|
|
|
>
|
2022-01-02 17:16:15 +01:00
|
|
|
{post.title}
|
|
|
|
</h5>
|
|
|
|
<p className={`
|
2022-06-09 13:55:11 +02:00
|
|
|
hidden md:block
|
2022-01-02 17:16:15 +01:00
|
|
|
m-0 p-1 -mt-2
|
|
|
|
text-neutral-content
|
|
|
|
leading-normal text-sm font-normal
|
2022-05-29 18:44:32 +02:00
|
|
|
opacity-70
|
2022-06-09 13:55:11 +02:00
|
|
|
`}{ ...textShadow}>
|
2022-05-29 18:44:32 +02:00
|
|
|
<TimeAgo date={post.date} /> by <strong>{post.author}</strong>
|
2022-01-02 17:16:15 +01:00
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</a>
|
|
|
|
</Link>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
|
|
|
|
const BlogIndexPage = (props) => {
|
|
|
|
const app = useApp()
|
2022-05-29 18:44:32 +02:00
|
|
|
const { t } = useTranslation()
|
2022-01-02 17:16:15 +01:00
|
|
|
|
|
|
|
return (
|
2022-05-29 18:44:32 +02:00
|
|
|
<Page app={app} title={t('blog')} slug='blog'>
|
2022-06-09 19:33:27 +02:00
|
|
|
<div className="grid grid-cols-1 gap-4 lg:grid-cols-2 max-w-7xl">
|
2022-05-29 18:44:32 +02:00
|
|
|
{props.posts.map(post => <Preview app={app} post={post} key={post.slug}/>)
|
2022-01-02 17:16:15 +01:00
|
|
|
}
|
|
|
|
</div>
|
|
|
|
</Page>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default BlogIndexPage
|
2022-05-29 18:44:32 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* getStaticProps() is used to fetch data at build-time.
|
|
|
|
*
|
|
|
|
* On this page, it is loading the blog content from strapi.
|
|
|
|
*
|
|
|
|
* This, in combination with getStaticPaths() below means this
|
|
|
|
* page will be used to render/generate all blog content.
|
|
|
|
*
|
|
|
|
* To learn more, see: https://nextjs.org/docs/basic-features/data-fetching
|
|
|
|
*/
|
|
|
|
export async function getStaticProps({ params, locale }) {
|
|
|
|
|
|
|
|
const posts = await fetch(
|
2022-06-17 12:02:09 +02:00
|
|
|
`${strapiHost}/blogposts?_locale=en&_sort=date:DESC&dev_eq=true`
|
2022-05-29 18:44:32 +02:00
|
|
|
)
|
|
|
|
.then(response => response.json())
|
|
|
|
.then(data => data)
|
|
|
|
.catch(err => console.log(err))
|
|
|
|
|
|
|
|
return {
|
|
|
|
props: {
|
|
|
|
posts: posts.map(post => ({
|
|
|
|
slug: post.slug,
|
|
|
|
title: post.title,
|
|
|
|
date: post.date,
|
|
|
|
author: post.author.displayname,
|
|
|
|
image: strapiImage(post.image, ['medium']),
|
|
|
|
})),
|
|
|
|
...(await serverSideTranslations(locale)),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|