Updated to always be string[]

This commit is contained in:
qwsdcvghyu89
2026-06-17 08:24:02 +10:00
parent e190a5411f
commit e570974f06
+6 -9
View File
@@ -1,18 +1,15 @@
import { readFileSync } from 'fs';
import type { ChapterView, TextFragment } from '../types.ts';
import type { ChapterView } from '../types.ts';
interface ChapterRow {
chapter: number;
contents: string[] | TextFragment[];
contents: string[];
}
function readChapterContents(filePath: string, hasStyle: boolean): string[] | TextFragment[] {
function readChapterContents(filePath: string): string[] {
try {
const raw = readFileSync(filePath, 'utf-8');
if (hasStyle) {
return JSON.parse(raw) as TextFragment[];
}
return raw.split(/[\n\r]+/).map(l => l.trim()).filter(Boolean);
const fragments = JSON.parse(readFileSync(filePath, 'utf-8')) as Array<{ body: string }>;
return fragments.map(f => f.body).filter(Boolean);
} catch {
return [];
}
@@ -21,7 +18,7 @@ function readChapterContents(filePath: string, hasStyle: boolean): string[] | Te
export function renderJson(view: ChapterView): string {
const rows: ChapterRow[] = view.chapters.map((chapter, i) => ({
chapter: view.min + i,
contents: readChapterContents(chapter.path, chapter.hasStyle),
contents: readChapterContents(chapter.path),
}));
return JSON.stringify(rows);
}