From 92a51780956d02451870eed5fa2ec3d996eb33ec Mon Sep 17 00:00:00 2001 From: Yassine Doghri Date: Thu, 9 Mar 2023 11:43:52 +0000 Subject: [PATCH] fix: get astro pages' full paths using fdir's withFullPaths instead of withRelativePaths fixes #135 --- src/cli/generate.ts | 12 +++++++----- src/cli/utils.ts | 4 ++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/cli/generate.ts b/src/cli/generate.ts index 8cd00ba..b674950 100644 --- a/src/cli/generate.ts +++ b/src/cli/generate.ts @@ -2,7 +2,7 @@ import fs from "fs"; import { resolve } from "pathe"; import { AstroI18nextConfig } from "../types"; import { - getAstroPagesPath, + getAstroPagesFullPaths, createFiles, FileToGenerate, generateLocalizedFrontmatter, @@ -30,12 +30,14 @@ export const generate = ( const start = process.hrtime(); // default locale page paths - const astroPagesPaths = showDefaultLocale - ? getAstroPagesPath(inputPath, defaultLocale, locales) - : getAstroPagesPath(inputPath, undefined, locales); + const astroPagesFullPaths = showDefaultLocale + ? getAstroPagesFullPaths(inputPath, defaultLocale, locales) + : getAstroPagesFullPaths(inputPath, undefined, locales); const filesToGenerate: FileToGenerate[] = []; - astroPagesPaths.forEach(async function (astroFilePath: string) { + astroPagesFullPaths.forEach(async function (astroFileFullPath: string) { + const astroFilePath = astroFileFullPath.replace(resolve(inputPath), ""); + const inputFilePath = showDefaultLocale ? [inputPath, defaultLocale, astroFilePath].join("/") : [inputPath, astroFilePath].join("/"); diff --git a/src/cli/utils.ts b/src/cli/utils.ts index c242726..ec822b6 100644 --- a/src/cli/utils.ts +++ b/src/cli/utils.ts @@ -120,7 +120,7 @@ export const generateLocalizedFrontmatter = ( * @param childDirToCrawl will make the function crawl inside the given * `childDirToCrawl` (doesn't take paths, only dirname). */ -export const getAstroPagesPath = ( +export const getAstroPagesFullPaths = ( pagesDirectoryPath: string, childDirToCrawl: AstroI18nextConfig["defaultLocale"] | undefined = undefined, locales: AstroI18nextConfig["locales"] = [] @@ -131,7 +131,7 @@ export const getAstroPagesPath = ( (filepath) => !isFileHidden(filepath) && filepath.endsWith(".astro") ) .exclude((dirName) => locales.includes(dirName)) - .withRelativePaths(); + .withFullPaths(); return childDirToCrawl ? (api