| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- import { Book, BookEntryKind } from "@/types/book";
- export type FlattenedBookEntry = {
- id: string;
- title: string;
- kind: BookEntryKind;
- order: number;
- content: string[];
- sectionId: string;
- sectionTitle: string;
- sectionKind: BookEntryKind;
- flatIndex: number;
- };
- export function getBookEntries(book: Book): FlattenedBookEntry[] {
- return book.sections.flatMap((section) =>
- section.entries.map((entry) => ({
- ...entry,
- sectionId: section.id,
- sectionTitle: section.title,
- sectionKind: section.kind,
- flatIndex: 0
- }))
- ).map((entry, index) => ({
- ...entry,
- flatIndex: index
- }));
- }
- export function getBookContentCount(book: Book) {
- return getBookEntries(book).length;
- }
- export function getBookStructureStats(book: Book) {
- const entries = getBookEntries(book);
- return {
- loreCount: entries.filter((item) => item.kind === "lore").length,
- novelCount: entries.filter((item) => item.kind === "novel").length
- };
- }
|