Skip to content

Commit 5b3014a

Browse files
committed
fix: fixed static deployment
1 parent f02b01c commit 5b3014a

File tree

4 files changed

+33
-39
lines changed

4 files changed

+33
-39
lines changed

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,35 @@ import { notFound } from 'next/navigation';
1111
import type { FC } from 'react';
1212

1313
import * as basePage from '#site/app/[locale]/page';
14+
import { provideBlogPosts } from '#site/next-data/providers/blogData';
1415
import { ENABLE_STATIC_EXPORT } from '#site/next.constants.mjs';
15-
import { BLOG_DYNAMIC_ROUTES } from '#site/next.dynamic.constants.mjs';
16+
import { blogData } from '#site/next.json.mjs';
1617
import { defaultLocale } from '#site/next.locales.mjs';
1718

1819
type DynamicStaticPaths = { path: Array<string>; locale: string };
1920
type DynamicParams = { params: Promise<DynamicStaticPaths> };
2021

22+
/**
23+
* This constant is used to create static routes on-the-fly that do not have a file-system
24+
* counterpart route. This is useful for providing routes with matching Layout Names
25+
* but that do not have Markdown content and a matching file for the route
26+
*
27+
* @type {Array<string>} A Map of pathname and Layout Name
28+
*/
29+
export const BLOG_DYNAMIC_ROUTES = [
30+
// Provides Routes for all Blog Categories
31+
...blogData.categories,
32+
// Provides Routes for all Blog Categories w/ Pagination
33+
...blogData.categories
34+
// retrieves the amount of pages for each blog category
35+
.map(c => [c, provideBlogPosts(c).pagination.pages])
36+
// creates a numeric array for each page and define a pathname for
37+
// each page for a category (i.e. blog/all/page/1)
38+
.map(([c, t]) => [...Array(t).keys()].map(p => `${c}/page/${p + 1}`))
39+
// flattens the array since we have a .map inside another .map
40+
.flat(),
41+
];
42+
2143
// This is the default Viewport Metadata
2244
// @see https://nextjs.org/docs/app/api-reference/functions/generate-viewport#generateviewport-function
2345
export const generateViewport = basePage.generateViewport;

apps/site/app/sitemap.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import type { MetadataRoute } from 'next';
22

3-
import {
4-
BASE_PATH,
5-
BASE_URL,
6-
EXTERNAL_LINKS_SITEMAP,
7-
} from '#site/next.constants.mjs';
8-
import { BLOG_DYNAMIC_ROUTES } from '#site/next.dynamic.constants.mjs';
3+
import { BLOG_DYNAMIC_ROUTES } from '#site/app/[locale]/blog/[...path]/page';
4+
import { BASE_PATH } from '#site/next.constants.mjs';
5+
import { BASE_URL } from '#site/next.constants.mjs';
6+
import { EXTERNAL_LINKS_SITEMAP } from '#site/next.constants.mjs';
97
import { dynamicRouter } from '#site/next.dynamic.mjs';
108
import { availableLocaleCodes, defaultLocale } from '#site/next.locales.mjs';
119

@@ -35,7 +33,7 @@ const sitemap = async (): Promise<MetadataRoute.Sitemap> => {
3533
});
3634

3735
const staticPaths = routes.map(r => getSitemapEntry(r, nonDefaultLocales));
38-
const blogPaths = BLOG_DYNAMIC_ROUTES.map(r => getSitemapEntry(r));
36+
const blogPaths = BLOG_DYNAMIC_ROUTES.map(r => getSitemapEntry(`blog/${r}`));
3937
const externalPaths = EXTERNAL_LINKS_SITEMAP.map(r => getSitemapEntry(r));
4038

4139
return [...staticPaths, ...blogPaths, ...externalPaths];

apps/site/next.dynamic.constants.mjs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,8 @@
11
'use strict';
22

3-
import { provideBlogPosts } from '#site/next-data/providers/blogData';
4-
import { blogData } from '#site/next.json.mjs';
5-
63
import { BASE_PATH, BASE_URL } from './next.constants.mjs';
74
import { siteConfig } from './next.json.mjs';
85

9-
/**
10-
* This constant is used to create static routes on-the-fly that do not have a file-system
11-
* counterpart route. This is useful for providing routes with matching Layout Names
12-
* but that do not have Markdown content and a matching file for the route
13-
*
14-
* @type {Array<string>} A Map of pathname and Layout Name
15-
*/
16-
export const BLOG_DYNAMIC_ROUTES = [
17-
// Provides Routes for all Blog Categories
18-
...blogData.categories.map(c => `blog/${c}`),
19-
// Provides Routes for all Blog Categories w/ Pagination
20-
...blogData.categories
21-
// retrieves the amount of pages for each blog category
22-
.map(c => [c, provideBlogPosts(c).pagination.pages])
23-
// creates a numeric array for each page and define a pathname for
24-
// each page for a category (i.e. blog/all/page/1)
25-
.map(([c, t]) => [...Array(t).keys()].map(p => `blog/${c}/page/${p + 1}`))
26-
// flattens the array since we have a .map inside another .map
27-
.flat(),
28-
];
29-
306
/**
317
* This is the default Next.js Page Metadata for all pages
328
*

apps/site/next.dynamic.mjs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@ import matter from 'gray-matter';
77
import { cache } from 'react';
88
import { VFile } from 'vfile';
99

10-
import {
11-
BASE_PATH,
12-
BASE_URL,
13-
DEFAULT_CATEGORY_OG_TYPE,
14-
ENABLE_STATIC_EXPORT,
15-
IS_DEV_ENV,
16-
} from './next.constants.mjs';
10+
import { BASE_PATH } from './next.constants.mjs';
11+
import { BASE_URL } from './next.constants.mjs';
12+
import { DEFAULT_CATEGORY_OG_TYPE } from './next.constants.mjs';
13+
import { ENABLE_STATIC_EXPORT } from './next.constants.mjs';
14+
import { IS_DEV_ENV } from './next.constants.mjs';
1715
import { PAGE_METADATA } from './next.dynamic.constants.mjs';
1816
import { getMarkdownFiles } from './next.helpers.mjs';
1917
import { siteConfig } from './next.json.mjs';

0 commit comments

Comments
 (0)