Skip to content

Commit c01d07f

Browse files
committed
refactor: updated logic in conditions
1 parent a54a9a6 commit c01d07f

3 files changed

Lines changed: 16 additions & 17 deletions

File tree

.github/workflows/build.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ jobs:
128128
NODE_OPTIONS: '--max_old_space_size=4096'
129129
# Used for API requests that require GitHub API scopes
130130
NEXT_GITHUB_API_KEY: ${{ secrets.GITHUB_TOKEN }}
131+
# We want to ensure that static exports for all locales are triggered only on `push` events to save resources
132+
# and time.
133+
NEXT_PUBLIC_STATIC_EXPORT_LOCALE: true
131134

132135
- name: Build Next.js (Static Default Locale)
133136
# We want to generate static output in the default language within Pull Requests
@@ -146,8 +149,8 @@ jobs:
146149
NODE_OPTIONS: '--max_old_space_size=4096'
147150
# Used for API requests that require GitHub API scopes
148151
NEXT_GITHUB_API_KEY: ${{ secrets.GITHUB_TOKEN }}
149-
# We want to ensure that the static export for default locale only happens on `pull_request_target` events
150-
NEXT_PUBLIC_STATIC_EXPORT_LOCALE: true
152+
# We want to ensure that static exports for all locales do not occur on `pull_request_target` events
153+
NEXT_PUBLIC_STATIC_EXPORT_LOCALE: false
151154

152155
- name: Sync Orama Cloud
153156
# We only want to sync the Orama Cloud production indexes on `push` events.

apps/site/app/[locale]/[...path]/page.tsx

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ export const generateMetadata = basePage.generateMetadata;
2525

2626
// Generates all possible static paths based on the locales and environment configuration
2727
// - Returns an empty array if static export is disabled (`ENABLE_STATIC_EXPORT` is false)
28-
// - If `ENABLE_STATIC_EXPORT_LOCALE` is true, generates paths only for the default locale
29-
// - Otherwise, generates paths for all available locales
28+
// - If `ENABLE_STATIC_EXPORT_LOCALE` is true, generates paths for all available locales
29+
// - Otherwise, generates paths only for the default locale
3030
// @see https://nextjs.org/docs/app/api-reference/functions/generate-static-params
3131
export const generateStaticParams = async () => {
3232
// Return an empty array if static export is disabled
@@ -43,17 +43,13 @@ export const generateStaticParams = async () => {
4343
);
4444
};
4545

46-
// Handles the case where static export is enabled but only for the default locale
47-
if (ENABLE_STATIC_EXPORT_LOCALE) {
48-
const routes = await getRoutesForLocale(defaultLocale.code);
49-
50-
return routes.sort();
51-
}
46+
// Determine which locales to include in the static export
47+
const locales = ENABLE_STATIC_EXPORT_LOCALE
48+
? availableLocaleCodes
49+
: [defaultLocale.code];
5250

5351
// Generates all possible routes for all available locales
54-
const routes = await Promise.all(
55-
availableLocaleCodes.map(getRoutesForLocale)
56-
);
52+
const routes = await Promise.all(locales.map(getRoutesForLocale));
5753

5854
return routes.flat().sort();
5955
};

apps/site/app/[locale]/page.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ export const generateMetadata = async (props: DynamicParams) => {
4242

4343
// Generates all possible static paths based on the locales and environment configuration
4444
// - Returns an empty array if static export is disabled (`ENABLE_STATIC_EXPORT` is false)
45-
// - If `ENABLE_STATIC_EXPORT_LOCALE` is true, generates paths only for the default locale
46-
// - Otherwise, generates paths for all available locales
45+
// - If `ENABLE_STATIC_EXPORT_LOCALE` is true, generates paths for all available locales
46+
// - Otherwise, generates paths only for the default locale
4747
// @see https://nextjs.org/docs/app/api-reference/functions/generate-static-params
4848
export const generateStaticParams = async () => {
4949
// Return an empty array if static export is disabled
@@ -53,8 +53,8 @@ export const generateStaticParams = async () => {
5353

5454
// Determine which locales to include in the static export
5555
const locales = ENABLE_STATIC_EXPORT_LOCALE
56-
? [defaultLocale.code]
57-
: availableLocaleCodes;
56+
? availableLocaleCodes
57+
: [defaultLocale.code];
5858

5959
const routes = await Promise.all(
6060
// Gets all mapped routes to the Next.js Routing Engine by Locale

0 commit comments

Comments
 (0)