diff options
| author | Paul Buetow <paul@buetow.org> | 2026-04-22 09:07:47 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-04-22 09:07:47 +0300 |
| commit | 519be7e7dd12cbe3c85f90cf06d65b377eb22a3c (patch) | |
| tree | 59bc012999bd03a26e5fa6c097741ede7b211296 /internal/comic/helpers.go | |
| parent | 24dd98eaa9759884b17f18c729d498af6ec70e9e (diff) | |
add logo
Diffstat (limited to 'internal/comic/helpers.go')
| -rw-r--r-- | internal/comic/helpers.go | 28 |
1 files changed, 28 insertions, 0 deletions
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) |
