Skip to content

Commit af65246

Browse files
committed
apply patch around process.cwd that fails in netlify server context
1 parent a1fccbd commit af65246

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/lib/utils/md.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@ import { toPosixPath } from "./relativePath"
1818

1919
import { ITutorial } from "@/pages/developers/tutorials"
2020

21-
const CURRENT_CONTENT_DIR = join(process.cwd(), CONTENT_DIR)
21+
function getCurrentDir() {
22+
return join(process.cwd(), CONTENT_DIR)
23+
}
2224

2325
const getPostSlugs = (dir: string, files: string[] = []) => {
24-
const contentDir = join(CURRENT_CONTENT_DIR, dir)
26+
const cdir = getCurrentDir()
27+
const contentDir = join(cdir, dir)
2528
// Temporal list of content pages allowed to be compiled
2629
// When a content page is migrated (and he components being used), should be added to this list
2730
const temporalAllowedPages = [
@@ -290,14 +293,12 @@ const getPostSlugs = (dir: string, files: string[] = []) => {
290293
if (fileExtension === ".md") {
291294
// If it is a .md file (allowed content page), push the path to the files array
292295
for (const page of temporalAllowedPages) {
293-
const fullPagePath = join(CURRENT_CONTENT_DIR, page)
296+
const fullPagePath = join(cdir, page)
294297

295298
if (name.includes(fullPagePath)) {
296299
files.push(
297300
toPosixPath(
298-
fullPagePath
299-
.replace(CURRENT_CONTENT_DIR, "")
300-
.replace("/index.md", "")
301+
fullPagePath.replace(cdir, "").replace("/index.md", "")
301302
)
302303
)
303304
}
@@ -320,7 +321,8 @@ export const getContentBySlug = (slug: string) => {
320321
}
321322
}
322323

323-
let fullPath = toPosixPath(join(CURRENT_CONTENT_DIR, realSlug))
324+
const dir = getCurrentDir()
325+
let fullPath = toPosixPath(join(dir, realSlug))
324326
let contentNotTranslated = false
325327

326328
// If content is not translated, use english content fallback
@@ -350,8 +352,9 @@ export const getContent = (dir: string) => {
350352
}
351353

352354
export const getTutorialsData = (locale: string): ITutorial[] => {
355+
const dir = getCurrentDir()
353356
const fullPath = join(
354-
CURRENT_CONTENT_DIR,
357+
dir,
355358
locale !== "en" ? `translations/${locale!}` : "",
356359
"developers/tutorials"
357360
)
@@ -362,7 +365,7 @@ export const getTutorialsData = (locale: string): ITutorial[] => {
362365

363366
tutorialData = languageTutorialFiles.map((dir) => {
364367
const filePath = join(
365-
CURRENT_CONTENT_DIR,
368+
dir,
366369
locale !== "en" ? `translations/${locale!}` : "",
367370
"developers/tutorials",
368371
dir,

0 commit comments

Comments
 (0)