2019-08-06 22:26:01 +02:00
|
|
|
import React from 'react'
|
|
|
|
import Link from 'next/link'
|
2019-11-28 05:16:19 +01:00
|
|
|
import { useRouter } from 'next/router'
|
2020-03-25 19:57:14 +01:00
|
|
|
import 'firebase/firestore'
|
2019-08-06 22:26:01 +02:00
|
|
|
|
2020-02-27 18:57:39 +01:00
|
|
|
export async function getStaticPaths() {
|
2020-02-08 04:09:54 +01:00
|
|
|
return {
|
|
|
|
paths: [
|
|
|
|
'/blog/post-1',
|
|
|
|
{ params: { post: 'post-2' } },
|
|
|
|
'/blog/[post3]',
|
|
|
|
'/blog/post-4',
|
|
|
|
'/blog/post.1',
|
|
|
|
'/blog/post.1', // handle duplicates
|
|
|
|
],
|
2020-02-27 13:23:28 +01:00
|
|
|
fallback: true,
|
2020-02-08 04:09:54 +01:00
|
|
|
}
|
2019-09-24 10:50:04 +02:00
|
|
|
}
|
2019-08-06 22:26:01 +02:00
|
|
|
|
2020-02-13 05:06:41 +01:00
|
|
|
let counter = 0
|
|
|
|
|
2020-02-27 18:57:39 +01:00
|
|
|
export async function getStaticProps({ params }) {
|
2019-09-24 10:50:04 +02:00
|
|
|
if (params.post === 'post-10') {
|
|
|
|
await new Promise(resolve => {
|
|
|
|
setTimeout(() => resolve(), 1000)
|
|
|
|
})
|
2019-08-06 22:26:01 +02:00
|
|
|
}
|
|
|
|
|
2019-10-17 17:52:13 +02:00
|
|
|
if (params.post === 'post-100') {
|
|
|
|
throw new Error('such broken..')
|
|
|
|
}
|
|
|
|
|
2020-02-13 05:06:41 +01:00
|
|
|
if (params.post === 'post-999') {
|
|
|
|
if (++counter < 3) {
|
|
|
|
throw new Error('try again..')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-24 10:50:04 +02:00
|
|
|
return {
|
|
|
|
props: {
|
2019-12-13 19:14:09 +01:00
|
|
|
params,
|
2019-09-24 10:50:04 +02:00
|
|
|
post: params.post,
|
2019-11-11 04:24:53 +01:00
|
|
|
time: (await import('perf_hooks')).performance.now(),
|
2019-09-24 10:50:04 +02:00
|
|
|
},
|
2019-11-11 04:24:53 +01:00
|
|
|
revalidate: 10,
|
2019-08-06 22:26:01 +02:00
|
|
|
}
|
|
|
|
}
|
2019-09-24 10:50:04 +02:00
|
|
|
|
2019-12-13 19:14:09 +01:00
|
|
|
export default ({ post, time, params }) => {
|
2019-09-24 10:50:04 +02:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<p>Post: {post}</p>
|
|
|
|
<span>time: {time}</span>
|
2019-12-13 19:14:09 +01:00
|
|
|
<div id="params">{JSON.stringify(params)}</div>
|
2019-11-28 05:16:19 +01:00
|
|
|
<div id="query">{JSON.stringify(useRouter().query)}</div>
|
2019-11-11 04:24:53 +01:00
|
|
|
<Link href="/">
|
|
|
|
<a id="home">to home</a>
|
2019-09-24 10:50:04 +02:00
|
|
|
</Link>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|