fallback true; revalidate 30; show simple loader
This commit is contained in:
1 parent
bc07643b11
commit
7d10ea27f0
1 file changed
+100
-87
+100
-87
@@ -15,6 +15,7 @@ import { Youtube } from '@/components/Youtube'
|
|||||||
import { createPage, createPageUrls } from '@/remote/factory'
|
import { createPage, createPageUrls } from '@/remote/factory'
|
||||||
import { paramsToSlug } from '@/remote/lib'
|
import { paramsToSlug } from '@/remote/lib'
|
||||||
import { PageGrid } from '@/components/PageGrid'
|
import { PageGrid } from '@/components/PageGrid'
|
||||||
|
import { useRouter } from 'next/router'
|
||||||
|
|
||||||
async function getUrls() {
|
async function getUrls() {
|
||||||
let urls = []
|
let urls = []
|
||||||
@@ -73,99 +74,110 @@ type Props = {
|
|||||||
tokens: Token[]
|
tokens: Token[]
|
||||||
}
|
}
|
||||||
|
|
||||||
const Index: NextPage<Props> = props => (
|
const Index: NextPage<Props> = props => {
|
||||||
<App
|
const router = useRouter()
|
||||||
contentStyle={{
|
if (router.isFallback) {
|
||||||
marginTop: 'var(--size-l)',
|
return (
|
||||||
marginBottom: 'var(--size-xl)',
|
<div>
|
||||||
}}
|
loading...
|
||||||
breadcrumbs={props.breadcrumb}
|
</div>
|
||||||
>
|
)
|
||||||
<Head>
|
}
|
||||||
<title>{props.title}</title>
|
|
||||||
{!props.meta ? null : (
|
|
||||||
<Meta meta={props.meta} />
|
|
||||||
)}
|
|
||||||
</Head>
|
|
||||||
|
|
||||||
<Page
|
return (
|
||||||
tags={props.tags}
|
<App
|
||||||
date={props.date ? new Date(props.date) : null}
|
contentStyle={{
|
||||||
|
marginTop: 'var(--size-l)',
|
||||||
|
marginBottom: 'var(--size-xl)',
|
||||||
|
}}
|
||||||
|
breadcrumbs={props.breadcrumb}
|
||||||
>
|
>
|
||||||
<article className={'article'}>
|
<Head>
|
||||||
{props.tokens.map((x, i) => {
|
<title>{props.title}</title>
|
||||||
switch (x.token) {
|
{!props.meta ? null : (
|
||||||
case 'text':
|
<Meta meta={props.meta} />
|
||||||
return (
|
)}
|
||||||
<Markdown
|
</Head>
|
||||||
key={i}
|
|
||||||
data={x.data}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
|
|
||||||
case 'html':
|
<Page
|
||||||
return (
|
tags={props.tags}
|
||||||
<Html
|
date={props.date ? new Date(props.date) : null}
|
||||||
key={i}
|
>
|
||||||
html={x.data}
|
<article className={'article'}>
|
||||||
/>
|
{props.tokens.map((x, i) => {
|
||||||
)
|
switch (x.token) {
|
||||||
|
case 'text':
|
||||||
case 'instagram':
|
return (
|
||||||
return (
|
<Markdown
|
||||||
<Html
|
key={i}
|
||||||
key={i}
|
data={x.data}
|
||||||
html={x.data.embed}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
|
|
||||||
case 'youtube':
|
|
||||||
return (
|
|
||||||
<Youtube
|
|
||||||
key={i}
|
|
||||||
url={x.data.url}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
|
|
||||||
case 'image':
|
|
||||||
return (
|
|
||||||
<figure key={i} className="kazimir__image">
|
|
||||||
<Image
|
|
||||||
src={x.data.src}
|
|
||||||
alt={x.data.alt}
|
|
||||||
width={x.data.width}
|
|
||||||
height={x.data.height}
|
|
||||||
layout={'responsive'}
|
|
||||||
/>
|
/>
|
||||||
<figcaption>{x.data.caption}</figcaption>
|
)
|
||||||
</figure>
|
|
||||||
)
|
|
||||||
|
|
||||||
case 'file':
|
case 'html':
|
||||||
return (
|
return (
|
||||||
<File key={i} {...x.data} />
|
<Html
|
||||||
)
|
key={i}
|
||||||
|
html={x.data}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
|
||||||
case 'grid':
|
case 'instagram':
|
||||||
return (
|
return (
|
||||||
<PageGrid
|
<Html
|
||||||
key={i}
|
key={i}
|
||||||
items={x.data.items}
|
html={x.data.embed}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
|
|
||||||
default:
|
case 'youtube':
|
||||||
return (
|
return (
|
||||||
<pre key={i}>
|
<Youtube
|
||||||
{JSON.stringify(x)}
|
key={i}
|
||||||
</pre>
|
url={x.data.url}
|
||||||
)
|
/>
|
||||||
}
|
)
|
||||||
})}
|
|
||||||
</article>
|
case 'image':
|
||||||
</Page>
|
return (
|
||||||
</App>
|
<figure key={i} className="kazimir__image">
|
||||||
)
|
<Image
|
||||||
|
src={x.data.src}
|
||||||
|
alt={x.data.alt}
|
||||||
|
width={x.data.width}
|
||||||
|
height={x.data.height}
|
||||||
|
layout={'responsive'}
|
||||||
|
/>
|
||||||
|
<figcaption>{x.data.caption}</figcaption>
|
||||||
|
</figure>
|
||||||
|
)
|
||||||
|
|
||||||
|
case 'file':
|
||||||
|
return (
|
||||||
|
<File key={i} {...x.data} />
|
||||||
|
)
|
||||||
|
|
||||||
|
case 'grid':
|
||||||
|
return (
|
||||||
|
<PageGrid
|
||||||
|
key={i}
|
||||||
|
items={x.data.items}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
|
||||||
|
default:
|
||||||
|
return (
|
||||||
|
<pre key={i}>
|
||||||
|
{JSON.stringify(x)}
|
||||||
|
</pre>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
})}
|
||||||
|
</article>
|
||||||
|
</Page>
|
||||||
|
</App>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
export const getStaticProps: GetStaticProps<any> = async ctx => {
|
export const getStaticProps: GetStaticProps<any> = async ctx => {
|
||||||
const slug = paramsToSlug(ctx.params.slug)
|
const slug = paramsToSlug(ctx.params.slug)
|
||||||
@@ -190,6 +202,7 @@ export const getStaticProps: GetStaticProps<any> = async ctx => {
|
|||||||
const tokens = page.tokens
|
const tokens = page.tokens
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
revalidate: 30,
|
||||||
props: {
|
props: {
|
||||||
tokens,
|
tokens,
|
||||||
title: page.title,
|
title: page.title,
|
||||||
@@ -205,7 +218,7 @@ export const getStaticPaths = async () => {
|
|||||||
const urls = await getUrls()
|
const urls = await getUrls()
|
||||||
|
|
||||||
return {
|
return {
|
||||||
fallback: false,
|
fallback: true,
|
||||||
paths: urls
|
paths: urls
|
||||||
.map(path => {
|
.map(path => {
|
||||||
const slug = tail(path.split('/'))
|
const slug = tail(path.split('/'))
|
||||||
|
|||||||
Reference in new issue
Block a user