1
0
Fork 0

Merge branch 'joost' of github.com:freesewing/freesewing into joost

This commit is contained in:
joostdecock 2023-07-21 18:20:29 +02:00
commit 4c285c4bc0
4 changed files with 108 additions and 2 deletions

View file

@ -53,6 +53,11 @@ const BlogPage = ({ locale, slug, page }) => {
export async function getStaticProps({ params, locale }) {
const { slug } = params
// if the slug isn't present in the prebuilt order, return 404
if (order[locale].indexOf(`blog/${slug}`) === -1) {
return { notFound: true }
}
return {
props: {
slug,
@ -66,6 +71,21 @@ export async function getStaticProps({ params, locale }) {
}
}
/*
* getStaticPaths() is used to specify for which routes (think URLs)
* this page should be used to generate the result.
*
* On this page, it is returning a truncated list of routes (think URLs) for all
* the mdx blog (markdown) content.
* That list comes from prebuild/blog-paths.mjs, which is built in the prebuild step
* and contains paths, titles, imageUrls, and intro for all blog posts.
*
* the fallback: 'blocking' property means that
* any pages that haven't been pre-generated
* will generate and cache the first time someone visits them
*
* To learn more, see: https://nextjs.org/docs/basic-features/data-fetching
*/
export const getStaticPaths = async () => {
return {
paths: getPostSlugPaths(posts),

View file

@ -69,6 +69,7 @@ const Preview = ({ post, t }) => (
</Link>
</div>
)
/*
* Each page MUST be wrapped in the PageWrapper component.
* You also MUST spread props.page into this wrapper component
@ -91,9 +92,20 @@ const BlogIndexPage = ({ posts, page, current, total }) => {
export default BlogIndexPage
/*
* getStaticProps() is used to fetch data at build-time.
*
* On this page, it fetches data for the blogs to be linked to on this page
*
* This, in combination with getStaticPaths() below means this
* page will be used to link to all blogs.
*
* To learn more, see: https://nextjs.org/docs/basic-features/data-fetching
*/
export async function getStaticProps({ locale, params }) {
const props = getPostIndexProps(params.page, posts[locale], meta)
// if there shouldn't be a page with these params, return 404
if (props === false) return { notFound: true }
return {
@ -109,6 +121,21 @@ export async function getStaticProps({ locale, params }) {
}
}
/*
* getStaticPaths() is used to specify for which routes (think URLs)
* this page should be used to generate the result.
*
* On this page, it is returning a truncated list of routes (think URLs) for pages that list and link to
* the mdx blog (markdown) content.
* That list comes from prebuild/blog-paths.mjs, which is built in the prebuild step
* and contains paths, titles, imageUrls, and intro for all blog posts.
*
* the fallback: 'blocking' property means that
* any pages that haven't been pre-generated
* will generate and cache the first time someone visits them
*
* To learn more, see: https://nextjs.org/docs/basic-features/data-fetching
*/
export const getStaticPaths = async () => {
return {
paths: getPostIndexPaths(posts, 'blog'),

View file

@ -9,14 +9,21 @@ import { PageWrapper, ns as pageNs } from 'shared/components/wrappers/page.mjs'
const namespaces = [...layoutNs, ...postNs, ...pageNs]
/*
* 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 ShowcasePage = ({ locale, slug, page }) => {
// function to load the correct markdown
const loader = useCallback(
() => import(`orgmarkdown/showcase/${slug}/${locale}.md`),
[slug, locale]
)
const { frontmatter, MDX } = useDynamicMdx(loader)
if (!MDX) return null
return (
<PageWrapper
{...page}
@ -39,7 +46,7 @@ const ShowcasePage = ({ locale, slug, page }) => {
/*
* getStaticProps() is used to fetch data at build-time.
*
* On this page, it is loading the showcase content from strapi.
* On this page, it it passes the name of the bundle to be loaded on the client.
*
* This, in combination with getStaticPaths() below means this
* page will be used to render/generate all showcase content.
@ -49,6 +56,11 @@ const ShowcasePage = ({ locale, slug, page }) => {
export async function getStaticProps({ params, locale }) {
const { slug } = params
// if the slug isn't present in the prebuilt order, return 404
if (order[locale].indexOf(`showcase/${slug}`) === -1) {
return { notFound: true }
}
return {
props: {
slug,
@ -62,6 +74,21 @@ export async function getStaticProps({ params, locale }) {
}
}
/*
* getStaticPaths() is used to specify for which routes (think URLs)
* this page should be used to generate the result.
*
* On this page, it is returning a truncated list of routes (think URLs) for all
* the mdx showcase (markdown) content.
* That list comes from prebuild/showcase-paths.mjs, which is built in the prebuild step
* and contains paths, titles, imageUrls, and intro for all showcase posts.
*
* the fallback: 'blocking' property means that
* any pages that haven't been pre-generated
* will generate and cache the first time someone visits them
*
* To learn more, see: https://nextjs.org/docs/basic-features/data-fetching
*/
export const getStaticPaths = async () => {
return {
paths: getPostSlugPaths(posts),

View file

@ -59,6 +59,12 @@ const Posts = ({ posts }) => {
)
}
/*
* 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 ShowcaseIndexPage = ({ posts, page, current, total }) => {
const { t } = useTranslation()
@ -75,9 +81,20 @@ const ShowcaseIndexPage = ({ posts, page, current, total }) => {
export default ShowcaseIndexPage
/*
* getStaticProps() is used to fetch data at build-time.
*
* On this page, it fetches data for the showcases to be linked to on this page
*
* This, in combination with getStaticPaths() below means this
* page will be used to link to all showcases.
*
* To learn more, see: https://nextjs.org/docs/basic-features/data-fetching
*/
export async function getStaticProps({ locale, params }) {
const props = getPostIndexProps(params.page, posts[locale], meta)
// if there shouldn't be a page with these params, return 404
if (props === false) return { notFound: true }
return {
@ -93,6 +110,21 @@ export async function getStaticProps({ locale, params }) {
}
}
/*
* getStaticPaths() is used to specify for which routes (think URLs)
* this page should be used to generate the result.
*
* On this page, it is returning a truncated list of routes (think URLs) for pages that list and link to
* the mdx showcase (markdown) content.
* That list comes from prebuild/showcase-paths.mjs, which is built in the prebuild step
* and contains paths, titles, imageUrls, and intro for all showcase posts.
*
* the fallback: 'blocking' property means that
* any pages that haven't been pre-generated
* will generate and cache the first time someone visits them
*
* To learn more, see: https://nextjs.org/docs/basic-features/data-fetching
*/
export const getStaticPaths = async () => {
return {
paths: getPostIndexPaths(posts, 'showcase'),