From 92008c0070b884af5c8f3080e1c6b30d26acf691 Mon Sep 17 00:00:00 2001 From: Evan Fiordeliso Date: Thu, 17 Jul 2025 09:08:29 -0400 Subject: [PATCH] Get subtitle and add indent helper to templater --- src/data-sources/Goodreads.ts | 12 +++++++++++- src/types.ts | 1 + src/utils/Templater.ts | 9 +++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/data-sources/Goodreads.ts b/src/data-sources/Goodreads.ts index 18fe0c2..1eccb87 100644 --- a/src/data-sources/Goodreads.ts +++ b/src/data-sources/Goodreads.ts @@ -169,8 +169,18 @@ export class Goodreads { }; } + let title = bookData.title; + let subtitle = ""; + + if (title.includes(": ")) { + const parts = title.split(": "); + subtitle = parts.pop()!; + title = parts.join(": "); + } + return { - title: bookData.title, + title, + subtitle, description: bookData.description, authors, series, diff --git a/src/types.ts b/src/types.ts index ad683b5..43d70c4 100644 --- a/src/types.ts +++ b/src/types.ts @@ -14,6 +14,7 @@ export interface Series { export interface Book { title: string; + subtitle: string; description: string; authors: Author[]; series: Series | null; diff --git a/src/utils/Templater.ts b/src/utils/Templater.ts index 5e18127..132033f 100644 --- a/src/utils/Templater.ts +++ b/src/utils/Templater.ts @@ -16,6 +16,15 @@ Handlebars.registerHelper("normalizeDesc", (desc: string) => { return desc.replace(/(\r\n|\n|\r)/gm, " ").trim(); }); +Handlebars.registerHelper("indent", (text: string, indent = " ") => { + return new Handlebars.SafeString( + text + .split("\n") + .map((line) => indent + line) + .join("\n") + ); +}); + export class Templater { public constructor(private readonly app: App) {}