fix: ssp
This commit is contained in:
parent
190e91f083
commit
8f27f005ef
4 changed files with 58 additions and 55 deletions
|
@ -8,29 +8,30 @@ import {
|
|||
} from 'next-mdx-remote-client/serialize'
|
||||
import { NextSeo } from 'next-seo'
|
||||
|
||||
export async function getStaticPaths () {
|
||||
const res = await fetchBasicPages(['path'])
|
||||
// export async function getStaticPaths () {
|
||||
// const res = await fetchBasicPages(['path'])
|
||||
|
||||
if (!res.ok) {
|
||||
throw new FailedFetchBasicPagesError(await res.text())
|
||||
}
|
||||
// if (!res.ok) {
|
||||
// throw new FailedFetchBasicPagesError(await res.text())
|
||||
// }
|
||||
|
||||
const pages = (await res.json()).data
|
||||
// const pages = (await res.json()).data
|
||||
|
||||
const paths = {
|
||||
paths: pages.map(page => ({
|
||||
params: {
|
||||
path: page.path?.split('/') // about/page -> [about, page]
|
||||
.filter(p => !!p) ?? [] // deal with paths starting with '/'
|
||||
}
|
||||
})),
|
||||
fallback: true // false or "blocking"
|
||||
}
|
||||
// const paths = {
|
||||
// paths: pages.map(page => ({
|
||||
// params: {
|
||||
// path: page.path?.split('/') // about/page -> [about, page]
|
||||
// .filter(p => !!p) ?? [] // deal with paths starting with '/'
|
||||
// }
|
||||
// })),
|
||||
// fallback: true // false or "blocking"
|
||||
// }
|
||||
|
||||
return paths
|
||||
}
|
||||
export async function getStaticProps ({ params }) {
|
||||
// return paths
|
||||
// }
|
||||
export async function getServerSideProps ({ params }) {
|
||||
const { path } = params
|
||||
console.log(params)
|
||||
const res = await fetchBasicPages([], {
|
||||
path: {
|
||||
_eq: path?.join('/') ?? null
|
||||
|
|
|
@ -4,27 +4,28 @@ import BookReview from '@/components/Book/BookReview'
|
|||
import { fetchBookReviews, markdownToHtml } from '@/services/content-service'
|
||||
import { FailedFetchBookReviewError, FailedFetchBookReviewsError } from '@/errors'
|
||||
|
||||
export async function getStaticPaths () {
|
||||
const res = await fetchBookReviews(['slug'], {
|
||||
status: 'published'
|
||||
})
|
||||
// export async function getStaticPaths () {
|
||||
// const res = await fetchBookReviews(['slug'], {
|
||||
// status: 'published'
|
||||
// })
|
||||
|
||||
if (!res.ok) {
|
||||
throw new FailedFetchBookReviewsError(await res.text())
|
||||
}
|
||||
// if (!res.ok) {
|
||||
// throw new FailedFetchBookReviewsError(await res.text())
|
||||
// }
|
||||
|
||||
const reviews = (await res.json()).data
|
||||
// const reviews = (await res.json()).data
|
||||
|
||||
return {
|
||||
paths: reviews.map(post => ({
|
||||
params: {
|
||||
slug: post.slug
|
||||
}
|
||||
})),
|
||||
fallback: false // false or "blocking"
|
||||
}
|
||||
}
|
||||
export const getStaticProps = async ({ params }) => {
|
||||
// return {
|
||||
// paths: reviews.map(post => ({
|
||||
// params: {
|
||||
// slug: post.slug
|
||||
// }
|
||||
// })),
|
||||
// fallback: false // false or "blocking"
|
||||
// }
|
||||
// }
|
||||
|
||||
export const getServerSideProps = async ({ params }) => {
|
||||
const { slug } = params
|
||||
|
||||
if (!slug) {
|
||||
|
|
|
@ -8,7 +8,7 @@ import { NextSeo } from 'next-seo'
|
|||
|
||||
export const Title = 'Library'
|
||||
|
||||
export async function getStaticProps () {
|
||||
export async function getServerSideProps () {
|
||||
const res = await fetchBookReviews()
|
||||
|
||||
if (!res.ok) {
|
||||
|
|
|
@ -4,27 +4,28 @@ import Article from '@/components/Article/Article'
|
|||
import { fetchPosts, markdownToHtml } from '@/services/content-service'
|
||||
import { FailedFetchPostError, FailedFetchPostsError } from '@/errors'
|
||||
|
||||
export async function getStaticPaths () {
|
||||
const res = await fetchPosts(['slug'], {
|
||||
status: 'published'
|
||||
})
|
||||
// export async function getStaticPaths () {
|
||||
// const res = await fetchPosts(['slug'], {
|
||||
// status: 'published'
|
||||
// })
|
||||
|
||||
if (!res.ok) {
|
||||
throw new FailedFetchPostsError(await res.text())
|
||||
}
|
||||
// if (!res.ok) {
|
||||
// throw new FailedFetchPostsError(await res.text())
|
||||
// }
|
||||
|
||||
const posts = (await res.json()).data
|
||||
// const posts = (await res.json()).data
|
||||
|
||||
return {
|
||||
paths: posts.map(post => ({
|
||||
params: {
|
||||
slug: post.slug
|
||||
}
|
||||
})),
|
||||
fallback: true // false or "blocking"
|
||||
}
|
||||
}
|
||||
export const getStaticProps = async ({ params }) => {
|
||||
// return {
|
||||
// paths: posts.map(post => ({
|
||||
// params: {
|
||||
// slug: post.slug
|
||||
// }
|
||||
// })),
|
||||
// fallback: true // false or "blocking"
|
||||
// }
|
||||
// }
|
||||
|
||||
export const getServerSideProps = async ({ params }) => {
|
||||
const { slug } = params
|
||||
const res = await fetchPosts([], {
|
||||
slug,
|
||||
|
|
Loading…
Add table
Reference in a new issue