From 519be7e7dd12cbe3c85f90cf06d65b377eb22a3c Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Wed, 22 Apr 2026 09:07:47 +0300 Subject: add logo --- internal/comic/helpers.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'internal/comic/helpers.go') diff --git a/internal/comic/helpers.go b/internal/comic/helpers.go index 6f5b5a8..1d51597 100644 --- a/internal/comic/helpers.go +++ b/internal/comic/helpers.go @@ -4,6 +4,8 @@ import ( "strings" ) +const maxPromptSlugLength = 48 + // slugify converts a comic title into a safe file-name component. func slugify(title string) string { title = strings.ToLower(strings.TrimSpace(title)) @@ -29,6 +31,32 @@ func slugify(title string) string { return slug } +func shortSlug(title, fallback string) string { + slug := slugify(title) + if slug == "comic" { + slug = fallback + } + if slug == "" { + slug = fallback + } + if len(slug) <= maxPromptSlugLength { + return slug + } + cut := strings.LastIndex(slug[:maxPromptSlugLength+1], "-") + if cut < 12 { + cut = maxPromptSlugLength + } + slug = strings.TrimRight(slug[:cut], "-") + if slug == "" { + return fallback + } + return slug +} + +func shortPromptSlugFromText(text string) string { + return shortSlug(text, "manual-prompt") +} + // splitIntoSections divides text into n sections, preferring paragraph boundaries. func splitIntoSections(text string, n int) []string { paragraphs := splitParagraphs(text) -- cgit v1.2.3