Skip to content

Instantly share code, notes, and snippets.

@manuel-schoebel
Last active September 19, 2023 12:00
Show Gist options
  • Save manuel-schoebel/0119ad84ef4bc4086dc33b7fad619058 to your computer and use it in GitHub Desktop.
Save manuel-schoebel/0119ad84ef4bc4086dc33b7fad619058 to your computer and use it in GitHub Desktop.
Example static rendering next app router
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