Something went wrong. Try again.
A free, open-source, self-hosted place to write a novel.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536export type MatterPosition = 'front' | 'back';
export const MATTER_TITLES: Record<MatterPosition, readonly string[]> = { front: ['Title page', 'Copyright', 'Dedication', 'Epigraph', 'Foreword', 'Preface'], back: ['Acknowledgments', 'About the author', 'Afterword', 'Appendix', 'Also by the author']};
export function isMatterPosition(value: unknown): value is MatterPosition { return value === 'front' || value === 'back';}
type Positioned = { matter?: MatterPosition | null };
export function matterPages<T extends Positioned>( chapters: readonly T[], position: MatterPosition): T[] { return chapters.filter((chapter) => chapter.matter === position);}
export function bodyChapters<T extends Positioned>(chapters: readonly T[]): T[] { return chapters.filter((chapter) => !chapter.matter);}
export function orderedBookChapters<T extends Positioned>(book: { parts?: { chapters?: T[]; deletedAt?: string | null }[]; chapters?: T[];}): T[] { return [ ...matterPages(book.chapters ?? [], 'front'), ...(book.parts ?? []).filter((part) => !part.deletedAt).flatMap((part) => part.chapters ?? []), ...bodyChapters(book.chapters ?? []), ...matterPages(book.chapters ?? [], 'back') ];}