-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
meta: refactor to an inteligent cache system
- Loading branch information
Showing
25 changed files
with
302 additions
and
151 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import provideBlogData from '@/next-data/providers/blogData'; | ||
import { defaultLocale } from '@/next.locales.mjs'; | ||
|
||
// We only support fetching these pages from the /en/ locale code | ||
const locale = defaultLocale.code; | ||
|
||
type StaticParams = { params: { category: string; locale: string } }; | ||
|
||
// This is the Route Handler for the `GET` method which handles the request | ||
// for generating our static data for the Node.js Website | ||
// @see https://nextjs.org/docs/app/building-your-application/routing/router-handlers | ||
export const GET = async (_: Request, { params }: StaticParams) => { | ||
const { posts, pagination } = await provideBlogData(params.category); | ||
|
||
return Response.json( | ||
{ posts, pagination }, | ||
{ status: posts.length ? 200 : 404 } | ||
); | ||
}; | ||
|
||
// This function generates the static paths that come from the dynamic segments | ||
// `en/next-data/[type]` and returns an array of all available static paths | ||
// this is useful for static exports, for example. | ||
// Note that differently from the App Router these don't get built at the build time | ||
// only if the export is already set for static export | ||
export const generateStaticParams = async () => { | ||
const { | ||
meta: { categories, pagination }, | ||
} = await provideBlogData(); | ||
|
||
return [ | ||
...categories.map(category => ({ category, locale })), | ||
...pagination.map(year => ({ category: `year-${year}`, locale })), | ||
]; | ||
}; | ||
|
||
// Enforces that this route is used as static rendering | ||
// @see https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config#dynamic | ||
export const dynamic = 'error'; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import provideReleaseData from '@/next-data/providers/releaseData'; | ||
import { defaultLocale } from '@/next.locales.mjs'; | ||
|
||
// We only support fetching these pages from the /en/ locale code | ||
const locale = defaultLocale.code; | ||
|
||
// This is the Route Handler for the `GET` method which handles the request | ||
// for generating our static data for the Node.js Website | ||
// @see https://nextjs.org/docs/app/building-your-application/routing/router-handlers | ||
export const GET = async () => { | ||
const releaseData = await provideReleaseData(); | ||
|
||
return Response.json(releaseData); | ||
}; | ||
|
||
// This function generates the static paths that come from the dynamic segments | ||
// `en/next-data/[type]` and returns an array of all available static paths | ||
// this is useful for static exports, for example. | ||
// Note that differently from the App Router these don't get built at the build time | ||
// only if the export is already set for static export | ||
export const generateStaticParams = async () => [{ locale }]; | ||
|
||
// Enforces that this route is used as static rendering | ||
// @see https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config#dynamic | ||
export const dynamic = 'error'; |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { ENABLE_STATIC_EXPORT, NEXT_DATA_URL } from '@/next.constants.mjs'; | ||
import type { BlogDataRSC } from '@/types'; | ||
|
||
const getBlogData = (category: string): Promise<BlogDataRSC> => { | ||
if (ENABLE_STATIC_EXPORT) { | ||
// Loads the data dynamically with lazy-loading to prevent data-generation | ||
// within the top level import | ||
return import('@/next-data/providers/blogData').then( | ||
({ default: provideBlogData }) => provideBlogData(category) | ||
); | ||
} | ||
|
||
// When we're on RSC with Server capabilities we prefer using Next.js Data Fetching | ||
// as this will load cached data from the server instead of generating data on the fly | ||
// this is extremely useful for ISR and SSG as it will not generate this data on every request | ||
return fetch(`${NEXT_DATA_URL}blog-data/${category}`).then(r => r.json()); | ||
}; | ||
|
||
export default getBlogData; |
Oops, something went wrong.