fix: csv loading
This commit is contained in:
parent
ea57cf8d2b
commit
831955e16e
|
|
@ -82,7 +82,8 @@ export function parseCSVString<T = Record<string, string>>(csvString: string, so
|
|||
columns: true,
|
||||
comment: '#',
|
||||
trim: true,
|
||||
skipEmptyLines: true
|
||||
skipEmptyLines: true,
|
||||
bom: true
|
||||
});
|
||||
|
||||
const result = records as Record<string, string>[];
|
||||
|
|
@ -112,28 +113,7 @@ export async function loadCSV<T = Record<string, string>>(pathOrContent: string)
|
|||
|
||||
// 从索引获取文件内容
|
||||
const content = await getIndexedData(pathOrContent);
|
||||
|
||||
// 解析 front matter
|
||||
const { frontmatter, remainingContent } = parseFrontMatter(content);
|
||||
|
||||
const records = parse(remainingContent, {
|
||||
columns: true,
|
||||
comment: '#',
|
||||
trim: true,
|
||||
skipEmptyLines: true
|
||||
});
|
||||
|
||||
const result = records as Record<string, string>[];
|
||||
// 添加 front matter 到结果中
|
||||
const csvResult = result as CSV<T>;
|
||||
if (frontmatter) {
|
||||
csvResult.frontmatter = frontmatter;
|
||||
for(const each of result){
|
||||
Object.assign(each, frontmatter);
|
||||
}
|
||||
}
|
||||
csvResult.sourcePath = pathOrContent;
|
||||
return csvResult;
|
||||
return parseCSVString<T>(content, pathOrContent);
|
||||
}
|
||||
|
||||
type JSONData = JSONArray | JSONObject | string | number | boolean | null;
|
||||
|
|
|
|||
Loading…
Reference in New Issue