This commit is contained in:
Aaron Yarborough 2025-05-02 23:36:19 +01:00
parent 190e91f083
commit 8f27f005ef
4 changed files with 58 additions and 55 deletions

View file

@ -8,29 +8,30 @@ import {
} from 'next-mdx-remote-client/serialize' } from 'next-mdx-remote-client/serialize'
import { NextSeo } from 'next-seo' import { NextSeo } from 'next-seo'
export async function getStaticPaths () { // export async function getStaticPaths () {
const res = await fetchBasicPages(['path']) // const res = await fetchBasicPages(['path'])
if (!res.ok) { // if (!res.ok) {
throw new FailedFetchBasicPagesError(await res.text()) // throw new FailedFetchBasicPagesError(await res.text())
} // }
const pages = (await res.json()).data // const pages = (await res.json()).data
const paths = { // const paths = {
paths: pages.map(page => ({ // paths: pages.map(page => ({
params: { // params: {
path: page.path?.split('/') // about/page -> [about, page] // path: page.path?.split('/') // about/page -> [about, page]
.filter(p => !!p) ?? [] // deal with paths starting with '/' // .filter(p => !!p) ?? [] // deal with paths starting with '/'
} // }
})), // })),
fallback: true // false or "blocking" // fallback: true // false or "blocking"
} // }
return paths // return paths
} // }
export async function getStaticProps ({ params }) { export async function getServerSideProps ({ params }) {
const { path } = params const { path } = params
console.log(params)
const res = await fetchBasicPages([], { const res = await fetchBasicPages([], {
path: { path: {
_eq: path?.join('/') ?? null _eq: path?.join('/') ?? null

View file

@ -4,27 +4,28 @@ import BookReview from '@/components/Book/BookReview'
import { fetchBookReviews, markdownToHtml } from '@/services/content-service' import { fetchBookReviews, markdownToHtml } from '@/services/content-service'
import { FailedFetchBookReviewError, FailedFetchBookReviewsError } from '@/errors' import { FailedFetchBookReviewError, FailedFetchBookReviewsError } from '@/errors'
export async function getStaticPaths () { // export async function getStaticPaths () {
const res = await fetchBookReviews(['slug'], { // const res = await fetchBookReviews(['slug'], {
status: 'published' // status: 'published'
}) // })
if (!res.ok) { // if (!res.ok) {
throw new FailedFetchBookReviewsError(await res.text()) // throw new FailedFetchBookReviewsError(await res.text())
} // }
const reviews = (await res.json()).data // const reviews = (await res.json()).data
return { // return {
paths: reviews.map(post => ({ // paths: reviews.map(post => ({
params: { // params: {
slug: post.slug // slug: post.slug
} // }
})), // })),
fallback: false // false or "blocking" // fallback: false // false or "blocking"
} // }
} // }
export const getStaticProps = async ({ params }) => {
export const getServerSideProps = async ({ params }) => {
const { slug } = params const { slug } = params
if (!slug) { if (!slug) {

View file

@ -8,7 +8,7 @@ import { NextSeo } from 'next-seo'
export const Title = 'Library' export const Title = 'Library'
export async function getStaticProps () { export async function getServerSideProps () {
const res = await fetchBookReviews() const res = await fetchBookReviews()
if (!res.ok) { if (!res.ok) {

View file

@ -4,27 +4,28 @@ import Article from '@/components/Article/Article'
import { fetchPosts, markdownToHtml } from '@/services/content-service' import { fetchPosts, markdownToHtml } from '@/services/content-service'
import { FailedFetchPostError, FailedFetchPostsError } from '@/errors' import { FailedFetchPostError, FailedFetchPostsError } from '@/errors'
export async function getStaticPaths () { // export async function getStaticPaths () {
const res = await fetchPosts(['slug'], { // const res = await fetchPosts(['slug'], {
status: 'published' // status: 'published'
}) // })
if (!res.ok) { // if (!res.ok) {
throw new FailedFetchPostsError(await res.text()) // throw new FailedFetchPostsError(await res.text())
} // }
const posts = (await res.json()).data // const posts = (await res.json()).data
return { // return {
paths: posts.map(post => ({ // paths: posts.map(post => ({
params: { // params: {
slug: post.slug // slug: post.slug
} // }
})), // })),
fallback: true // false or "blocking" // fallback: true // false or "blocking"
} // }
} // }
export const getStaticProps = async ({ params }) => {
export const getServerSideProps = async ({ params }) => {
const { slug } = params const { slug } = params
const res = await fetchPosts([], { const res = await fetchPosts([], {
slug, slug,