Skip to content

Commit

Permalink
fix: attempt to use platform-specific separator
Browse files Browse the repository at this point in the history
  • Loading branch information
ovflowd committed Aug 10, 2023
1 parent 6cf4383 commit 0c1e079
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
6 changes: 6 additions & 0 deletions next.constants.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ export const DEFAULT_LOCALE_CODE = defaultLocale.code;
*/
export const LEGACY_JAVASCRIPT_FILE = `${BASE_PATH}/static/js/legacyMain.js`;

/**
* This is the current Node.js Working directory. We usually use it to resolve pathnames
* relative to the content of the Node.js Website.
*/
export const CURRENT_WORKING_DIRECTORY = process.cwd();

/**
* This is a list of all static routes or pages from the Website that we do not
* want to allow to be statically built on our Static Export Build.
Expand Down
11 changes: 8 additions & 3 deletions next.dynamic.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ import rehypeSlug from 'rehype-slug';
import { serialize } from 'next-mdx-remote/serialize';
import { availableLocales } from './next.locales.mjs';
import { getMarkdownFiles } from './next.helpers.mjs';
import { DEFAULT_LOCALE_CODE, MD_EXTENSION_REGEX } from './next.constants.mjs';
import {
DEFAULT_LOCALE_CODE,
MD_EXTENSION_REGEX,
CURRENT_WORKING_DIRECTORY,
} from './next.constants.mjs';

// allows us to run a glob to get markdown files based on a language folder
const getPathsByLanguage = async (locale = DEFAULT_LOCALE_CODE, ignored = []) =>
getMarkdownFiles(process.cwd(), `pages/${locale}`, ignored);
getMarkdownFiles(CURRENT_WORKING_DIRECTORY, `pages/${locale}`, ignored);

/**
* This method is responsible for generating a Collection of all available paths that
Expand All @@ -41,6 +45,7 @@ const getAllPaths = async () => {
sourcePages.map(filename => {
// remove the index.md(x) suffix from a pathname
let pathname = filename.replace(MD_EXTENSION_REGEX, '');

// remove trailing slash for correct Windows pathing of the index files
if (pathname.length > 1 && pathname.endsWith(sep)) {
pathname = pathname.substring(0, pathname.length - 1);
Expand Down Expand Up @@ -110,7 +115,7 @@ export const getMarkdownFile = (

// gets the full pathname for the file (absolute path)
metadata.filename = join(
process.cwd(),
CURRENT_WORKING_DIRECTORY,
'pages',
localeToUse,
route.filename
Expand Down
5 changes: 4 additions & 1 deletion pages/[...path].tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { sep } from 'node:path';
import Theme from '@/theme';
import * as nextDynamic from '@/next.dynamic.mjs';
import * as nextConstants from '@/next.constants.mjs';
Expand Down Expand Up @@ -28,7 +29,9 @@ const getRouteWrite = (pathname: string) =>

// This maps a pathname into an actual route object that can be used
const mapPathnameToRoute = (pathname: string) => ({
params: { path: pathname.split('/') },
// we use a platform-specific separator to split the pathname
// since we're using filepaths here and not URL paths
params: { path: pathname.split(sep) },
});

// This method receives the props from `getStaticProps` and renders/builds the Markdown
Expand Down

0 comments on commit 0c1e079

Please sign in to comment.