-
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 data generation to server-side only (#6137)
* meta: refactor data generation to server-side only * chore: use import for this small data * meta: refactor to an inteligent cache system * chore: some code review * chore: final code review changes * meta: updated certain packages
- Loading branch information
Showing
47 changed files
with
621 additions
and
484 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 |
---|---|---|
@@ -1,9 +1,5 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
# if the generated files got tracked to this commit we revert them | ||
git reset public/node-releases-data.json | ||
git reset public/blog-posts-data.json | ||
|
||
# lint and format staged files | ||
npx lint-staged |
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 |
---|---|---|
@@ -1,35 +1,37 @@ | ||
import { NextResponse } from 'next/server'; | ||
|
||
import { generateWebsiteFeeds } from '@/next.data.mjs'; | ||
import { blogData } from '@/next.json.mjs'; | ||
import provideWebsiteFeeds from '@/next-data/providers/websiteFeeds'; | ||
import { siteConfig } from '@/next.json.mjs'; | ||
import { defaultLocale } from '@/next.locales.mjs'; | ||
|
||
// loads all the data from the blog-posts-data.json file | ||
const websiteFeeds = generateWebsiteFeeds(blogData); | ||
// We only support fetching these pages from the /en/ locale code | ||
const locale = defaultLocale.code; | ||
|
||
type StaticParams = { params: { feed: string } }; | ||
type StaticParams = { params: { feed: string; locale: string } }; | ||
|
||
// This is the Route Handler for the `GET` method which handles the request | ||
// for Blog Feeds within the Node.js Website | ||
// for the Node.js Website Blog Feeds (RSS) | ||
// @see https://nextjs.org/docs/app/building-your-application/routing/router-handlers | ||
export const GET = (_: Request, { params }: StaticParams) => { | ||
if (params.feed.includes('.xml') && websiteFeeds.has(params.feed)) { | ||
return new NextResponse(websiteFeeds.get(params.feed)?.rss2(), { | ||
headers: { 'Content-Type': 'application/xml' }, | ||
}); | ||
} | ||
|
||
return new NextResponse(null, { status: 404 }); | ||
export const GET = async (_: Request, { params }: StaticParams) => { | ||
// Generate the Feed for the given feed type (blog, releases, etc) | ||
const websiteFeed = await provideWebsiteFeeds(params.feed); | ||
|
||
return new NextResponse(websiteFeed, { | ||
headers: { 'Content-Type': 'application/xml' }, | ||
status: websiteFeed ? 200 : 404, | ||
}); | ||
}; | ||
|
||
// This function generates the static paths that come from the dynamic segments | ||
// `en/feeds/[feed]` 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 = () => | ||
[...websiteFeeds.keys()].map(feed => ({ feed, locale: defaultLocale.code })); | ||
|
||
// Enforces that this route is used as static rendering | ||
// `[locale]/feeds/[feed]` and returns an array of all available static paths | ||
// This is used for ISR static validation and generation | ||
export const generateStaticParams = async () => | ||
siteConfig.rssFeeds.map(feed => ({ feed: feed.file, locale })); | ||
|
||
// Forces that only the paths from `generateStaticParams` are allowed, giving 404 on the contrary | ||
// @see https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config#dynamicparams | ||
export const dynamicParams = false; | ||
|
||
// Enforces that this route is cached and static as much as possible | ||
// @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,42 @@ | ||
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 providing Blog Posts, Pagination for every supported Blog Category | ||
// this includes the `year-XXXX` categories for yearly archives (pagination) | ||
// @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 | ||
// `[locale]/next-data/blog-data/[category]` and returns an array of all available static paths | ||
// This is used for ISR static validation and generation | ||
export const generateStaticParams = async () => { | ||
// This metadata is the original list of all available categories and all available years | ||
// within the Node.js Website Blog Posts (2011, 2012...) | ||
const { meta } = await provideBlogData(); | ||
|
||
return [ | ||
...meta.categories.map(category => ({ category, locale })), | ||
...meta.pagination.map(year => ({ category: `year-${year}`, locale })), | ||
]; | ||
}; | ||
|
||
// Forces that only the paths from `generateStaticParams` are allowed, giving 404 on the contrary | ||
// @see https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config#dynamicparams | ||
export const dynamicParams = false; | ||
|
||
// Enforces that this route is cached and static as much as possible | ||
// @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,27 @@ | ||
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 static data related to the Node.js Release Data | ||
// @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 | ||
// `[locale]/next-data/release-data/` and returns an array of all available static paths | ||
// This is used for ISR static validation and generation | ||
export const generateStaticParams = async () => [{ locale }]; | ||
|
||
// Forces that only the paths from `generateStaticParams` are allowed, giving 404 on the contrary | ||
// @see https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config#dynamicparams | ||
export const dynamicParams = false; | ||
|
||
// 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 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,24 @@ | ||
import type { FC } from 'react'; | ||
|
||
import ActiveLink from '@/components/Common/ActiveLink'; | ||
import { useSiteNavigation } from '@/hooks/server'; | ||
|
||
const TopNavigation: FC = () => { | ||
const { navigationItems } = useSiteNavigation(); | ||
|
||
return ( | ||
<nav aria-label="primary"> | ||
<ul className="list-divider-pipe"> | ||
{navigationItems.map(({ link, text }) => ( | ||
<li key={link}> | ||
<ActiveLink href={link} allowSubPath> | ||
{text} | ||
</ActiveLink> | ||
</li> | ||
))} | ||
</ul> | ||
</nav> | ||
); | ||
}; | ||
|
||
export default TopNavigation; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
'use client'; | ||
|
||
import useBaseSiteNavigation from '@/hooks/useBaseSiteNavigation'; | ||
const useSiteNavigation = () => { | ||
throw new Error('Attempted to call useSiteNavigation from RCC'); | ||
}; | ||
|
||
export default useBaseSiteNavigation; | ||
export default useSiteNavigation; |
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.
Oops, something went wrong.