1
0
Fork 0
freesewing/sites/freesewing.org/pages/blog/index.js
Joost De Cock e4035b2509 chore: Re-structure workspaces, enforce build order
These are some changes in the way the monorepo is structured,
that are aimed at making it easier to get started.

There are two important changes:

**Multiple workspaces**

We had a yarn workspaces setup at `packages/*`. But our monorepo has
grown to 92 packages which can be overwhelming for people not familiar
with the package names.

To remedy this, I've split it into 4 different workspaces:

- `designs/*`: Holds FreeSewing designs (think patterns)
- `plugins/*`: Holds FreeSewing plugins
- `packages/*`: Holds other packages published on NPM
- `sites/*`: Holds software that is not published as an NPM package,
  such as our various websites and backend API

This should make it easier to find things, and to answer questions like
*where do I find the code for the plugins*.

**Updated reconfigure script to handle build order**

One problem when bootstrapping the repo is inter-dependencies between
packages. For example, building a pattern will only work once
`plugin-bundle` is built. Which will only work once all plugins in the
bundle or built. And that will only work when `core` is built, and so
on.

This can be frustrating for new users as `yarn buildall` will fail.
And it gets overlooked by seasoned devs because they're likely to have
every package built in their repo so this issue doesn't concern them.

To remedy this, we now have a `config/build-order.mjs` file and the
updated `/scripts/reconfigure.mjs` script will enforce the build order
so that things *just work*.
2022-06-16 17:11:31 +02:00

107 lines
3.2 KiB
JavaScript

import Page from 'site/components/wrappers/page.js'
import useApp from 'site/hooks/useApp.js'
import Link from 'next/link'
import TimeAgo from 'react-timeago'
import { strapiHost } from 'shared/config/freesewing.mjs'
import { strapiImage } from 'shared/utils.js'
import { useTranslation } from 'next-i18next'
import { serverSideTranslations } from 'next-i18next/serverSideTranslations'
const strapi = "https://posts.freesewing.org"
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 = ({ app, post }) => (
<div className="shadow rounded-lg">
<Link href={`/blog/${post.slug}`}>
<a title={post.title} className="hover:underline">
<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})`,
backgroundSize: 'cover',
}}>
<div className="grow"></div>
<div className="text-right mb-3 lg:mb-8">
<div className={`
bg-neutral text-neutral-content bg-opacity-40 text-right
px-4 py-1
lg:px-8 lg:py-4
`}>
<h5 className={`
text-neutral-content
text-xl font-bold
md:text-2xl md:font-normal
xl:text-3xl
`} {...textShadow}
>
{post.title}
</h5>
<p className={`
hidden md:block
m-0 p-1 -mt-2
text-neutral-content
leading-normal text-sm font-normal
opacity-70
`}{ ...textShadow}>
<TimeAgo date={post.date} /> by <strong>{post.author}</strong>
</p>
</div>
</div>
</div>
</a>
</Link>
</div>
)
const BlogIndexPage = (props) => {
const app = useApp()
const { t } = useTranslation()
return (
<Page app={app} title={t('blog')} slug='blog'>
<div className="grid grid-cols-1 gap-4 lg:grid-cols-2 max-w-7xl">
{props.posts.map(post => <Preview app={app} post={post} key={post.slug}/>)
}
</div>
</Page>
)
}
export default BlogIndexPage
/*
* 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(
`${strapiHost}/blogposts?_locale=${locale}&_sort=date:DESC&dev_ne=true`
)
.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)),
}
}
}