mirror of
https://github.com/hanzo-docs/docs.git
synced 2026-10-26 23:49:51 +00:00
Core: Ignore numeric locale file name
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'fumadocs-core': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Ignore numeric locale file name
|
||||||
@@ -34,7 +34,7 @@ export function parseFilePath(path: string): FileInfo {
|
|||||||
.filter((p) => p.length > 0)
|
.filter((p) => p.length > 0)
|
||||||
.join('/');
|
.join('/');
|
||||||
|
|
||||||
const [name, locale] = nameWithLocale.split('.');
|
const [name, locale] = getLocale(nameWithLocale);
|
||||||
return {
|
return {
|
||||||
dirname,
|
dirname,
|
||||||
name,
|
name,
|
||||||
@@ -47,7 +47,7 @@ export function parseFilePath(path: string): FileInfo {
|
|||||||
export function parseFolderPath(path: string): FileInfo {
|
export function parseFolderPath(path: string): FileInfo {
|
||||||
const segments = splitPath(slash(path));
|
const segments = splitPath(slash(path));
|
||||||
const base = segments.at(-1) ?? '';
|
const base = segments.at(-1) ?? '';
|
||||||
const [name, locale] = base.split('.');
|
const [name, locale] = getLocale(base);
|
||||||
const flattenedPath = segments.join('/');
|
const flattenedPath = segments.join('/');
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -59,6 +59,15 @@ export function parseFolderPath(path: string): FileInfo {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getLocale(name: string): [string, string?] {
|
||||||
|
const sep = name.lastIndexOf('.');
|
||||||
|
if (sep === -1) return [name];
|
||||||
|
const locale = name.slice(sep + 1);
|
||||||
|
|
||||||
|
if (/\d+/.exec(locale)) return [name];
|
||||||
|
return [name.slice(0, sep), locale];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param path - Relative path
|
* @param path - Relative path
|
||||||
* @returns Normalized path, with no trailing/leading slashes
|
* @returns Normalized path, with no trailing/leading slashes
|
||||||
|
|||||||
@@ -64,6 +64,13 @@ describe('Path utilities', () => {
|
|||||||
path: 'nested/test.cn.mdx',
|
path: 'nested/test.cn.mdx',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
expect(parseFilePath('nested/test.01.mdx')).toEqual({
|
||||||
|
dirname: 'nested',
|
||||||
|
name: 'test.01',
|
||||||
|
flattenedPath: 'nested/test.01',
|
||||||
|
path: 'nested/test.01.mdx',
|
||||||
|
});
|
||||||
|
|
||||||
expect(parseFilePath('nested\\test.cn.mdx')).toEqual(
|
expect(parseFilePath('nested\\test.cn.mdx')).toEqual(
|
||||||
parseFilePath('nested/test.cn.mdx'),
|
parseFilePath('nested/test.cn.mdx'),
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user