fix(i18n): fix that unable to delete page with SINGLE_FILE i18n structure (#6218)

fixes that getFilePaths returns same path twice when i18n structure is SINGLE_FILE
This commit is contained in:
Manoj Bahuguna 2022-02-17 17:49:10 +05:30 committed by GitHub
parent 17230d1464
commit a14580a754
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

View File

@ -181,6 +181,17 @@ describe('i18n', () => {
), ),
).toEqual(['src/content/en/index.md', 'src/content/de/index.md']); ).toEqual(['src/content/en/index.md', 'src/content/de/index.md']);
}); });
it('should return array with single path when structure is I18N_STRUCTURE.SINGLE_FILE', () => {
expect(
i18n.getFilePaths(
fromJS({
i18n: { structure: i18n.I18N_STRUCTURE.SINGLE_FILE, locales: ['en', 'de'] },
}),
...args,
),
).toEqual(['src/content/index.md']);
});
}); });
describe('normalizeFilePath', () => { describe('normalizeFilePath', () => {

View File

@ -114,6 +114,11 @@ export function getFilePaths(
slug: string, slug: string,
) { ) {
const { structure, locales } = getI18nInfo(collection) as I18nInfo; const { structure, locales } = getI18nInfo(collection) as I18nInfo;
if (structure === I18N_STRUCTURE.SINGLE_FILE) {
return [path];
}
const paths = locales.map(locale => const paths = locales.map(locale =>
getFilePath(structure as I18N_STRUCTURE, extension, path, slug, locale), getFilePath(structure as I18N_STRUCTURE, extension, path, slug, locale),
); );