Skip to content

Commit 2671876

Browse files
author
Teo
authored
Issue #20 fix blog posts on staying static (#757)
* Issue #20: Re-enables ISR so posts refresh automatically * Issue #20: Keep ISR in production, skip it for previews
1 parent 5e29f6b commit 2671876

1 file changed

Lines changed: 7 additions & 18 deletions

File tree

src/pages/index.page.tsx

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,12 @@ export default function HomePage({
3636
}
3737

3838
export async function getStaticProps() {
39-
try {
40-
const posts = await getBlogspotPosts();
41-
const props = { blogPosts: posts.slice(0, 8) };
39+
const posts = await getBlogspotPosts().catch(() => []);
40+
const props = { blogPosts: posts.slice(0, 8) };
4241

43-
// On Netlify we serve fully static to avoid ISR function crashes
44-
if (process.env.NETLIFY) {
45-
return { props };
46-
}
47-
48-
return { props, revalidate: 3600 };
49-
} catch {
50-
const props = { blogPosts: [] };
51-
52-
if (process.env.NETLIFY) {
53-
return { props };
54-
}
55-
56-
return { props, revalidate: 600 };
57-
}
42+
const isDeployPreview = process.env.CONTEXT === "deploy-preview";
43+
if (isDeployPreview) {
44+
return { props };
45+
} // fully static for previews
46+
return { props, revalidate: 3600 }; // ISR for prod
5847
}

0 commit comments

Comments
 (0)