Last active
September 19, 2023 12:00
-
-
Save manuel-schoebel/0119ad84ef4bc4086dc33b7fad619058 to your computer and use it in GitHub Desktop.
Example static rendering next app router
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { readdirSync } from "fs"; | |
import path from "path"; | |
import { performance } from "perf_hooks"; | |
async function getBlogPosts(path: string) { | |
const postFiles = await readdirSync(path); | |
const posts = postFiles.map((name) => ({ name })); | |
console.log("posts", posts); | |
return posts; | |
} | |
export const revalidate = 5; // revalidate the data at most every 5 seconds | |
// Only working running a build version | |
export default async function Page() { | |
const start = performance.now(); | |
const posts = await getBlogPosts(path.resolve("./src/posts")); | |
const end = performance.now(); | |
console.log(`Duration: ${end - start} ms`); | |
return ( | |
<> | |
{posts.map((p) => ( | |
<h2 key={p.name}>{p.name}</h2> | |
))} | |
</> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment