From 6c884da0cbe65689bf089951cb5e621d121416e6 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Tue, 21 Apr 2026 10:01:54 +0300 Subject: Fix output paths and language-neutral prompts --- internal/comic/artist.go | 12 ++++++------ internal/comic/comic_test.go | 16 +++++++++++++++- internal/comic/localization.go | 10 +++++----- internal/comic/runner.go | 10 +++++++++- internal/config/config_test.go | 2 +- 5 files changed, 36 insertions(+), 14 deletions(-) (limited to 'internal') diff --git a/internal/comic/artist.go b/internal/comic/artist.go index 65fed3d..fd5dc60 100644 --- a/internal/comic/artist.go +++ b/internal/comic/artist.go @@ -360,12 +360,12 @@ func pageScriptForPage(panelScript [][]string, idx int) []string { func buildPanelLayout(section string, pagePanels []string) string { if len(pagePanels) == 4 && pagePanels[0] != "" && pagePanels[1] != "" && pagePanels[2] != "" && pagePanels[3] != "" { var sb strings.Builder - sb.WriteString("Раздели изображението точно на 4 различни панела в решетка 2×2. Панелите трябва да разказват сцената последователно и да останат ясно различни един от друг.\n") + sb.WriteString("Divide the image into exactly 4 distinct panels in a 2x2 grid. The panels must tell the scene in sequence and remain visually distinct from each other.\n") for i, panel := range pagePanels { if panel == "" { continue } - fmt.Fprintf(&sb, "Панел %d: %s\n", i+1, panel) + fmt.Fprintf(&sb, "Panel %d: %s\n", i+1, panel) } return sb.String() } @@ -378,15 +378,15 @@ func buildPanelLayout(section string, pagePanels []string) string { } excerpt += "…" } - return "Раздели изображението точно на 4 различни панела в решетка 2×2. Панелите трябва да разказват историята последователно от начало към край и да останат ясно различни.\n" + - "Откъс от историята:\n\n" + excerpt + "\n" + return "Divide the image into exactly 4 distinct panels in a 2x2 grid. The panels must tell the story in sequence from beginning to end and remain visually distinct.\n" + + "Story excerpt:\n\n" + excerpt + "\n" } func blurbBoxInstruction(blurb string) string { if strings.TrimSpace(blurb) == "" { - return "правоъгълно текстово поле (бял или кремав фон, тънка черна рамка) близо до дъното, в стил на класически синопсис на задната корица" + return "a rectangular text box near the bottom with a white or cream background and a thin black border, styled like a classic back-cover synopsis box" } - return fmt.Sprintf("правоъгълно текстово поле (бял или кремав фон, тънка черна рамка) близо до дъното, което показва този текст в курсив:\n %q", blurb) + return fmt.Sprintf("a rectangular text box near the bottom with a white or cream background and a thin black border, displaying this italic text:\n %q", blurb) } func errorsJoin(errs ...error) error { diff --git a/internal/comic/comic_test.go b/internal/comic/comic_test.go index 319c7b2..b1ea5ab 100644 --- a/internal/comic/comic_test.go +++ b/internal/comic/comic_test.go @@ -47,11 +47,25 @@ func TestBuildPanelLayoutUsesFallbackExcerpt(t *testing.T) { t.Parallel() got := buildPanelLayout("one two three four five", nil) - if !strings.Contains(got, "Откъс от историята") { + if !strings.Contains(got, "Story excerpt") { t.Fatalf("buildPanelLayout() = %q", got) } } +func TestComicOutputDirDoesNotDuplicateComicsSegment(t *testing.T) { + t.Parallel() + + if got, want := comicOutputDir("comics", "slug"), filepath.Join("comics", "slug"); got != want { + t.Fatalf("comicOutputDir() = %q, want %q", got, want) + } + if got, want := comicOutputDir(".", "slug"), filepath.Join(".", "comics", "slug"); got != want { + t.Fatalf("comicOutputDir() = %q, want %q", got, want) + } + if got, want := comicOutputDir("/tmp/out", "slug"), filepath.Join("/tmp/out", "comics", "slug"); got != want { + t.Fatalf("comicOutputDir() = %q, want %q", got, want) + } +} + func TestCopyGalleryPNGsToComicsGallery(t *testing.T) { t.Parallel() diff --git a/internal/comic/localization.go b/internal/comic/localization.go index 6eb2a0d..941e741 100644 --- a/internal/comic/localization.go +++ b/internal/comic/localization.go @@ -13,9 +13,9 @@ func localizedBrandName(language, script string) string { func localizedScriptName(script string) string { switch { case strings.EqualFold(script, "Cyrillic"): - return "кирилица" + return "Cyrillic" case strings.EqualFold(script, "Latin"): - return "латиница" + return "Latin" default: return script } @@ -27,11 +27,11 @@ func localizedLanguageName(language, script string) string { } switch { case strings.EqualFold(language, "English"): - return "английски" + return "English" case strings.EqualFold(language, "German"): - return "немски" + return "German" case strings.EqualFold(language, "French"): - return "френски" + return "French" default: return language } diff --git a/internal/comic/runner.go b/internal/comic/runner.go index 5843aab..00275b8 100644 --- a/internal/comic/runner.go +++ b/internal/comic/runner.go @@ -128,7 +128,7 @@ func (r *Runner) Run(ctx context.Context, batchFile string) error { fmt.Printf(" Comic title: %q (slug: %s)\n", result.Title, slug) } - comicsDir := filepath.Join(dir, "comics", slug) + comicsDir := comicOutputDir(dir, slug) if err := os.MkdirAll(comicsDir, 0o755); err != nil { return fmt.Errorf("create comics dir %s: %w", comicsDir, err) } @@ -171,6 +171,14 @@ func (r *Runner) Run(ctx context.Context, batchFile string) error { return r.handleNarration(ctx, result.StoryText, slug, comicsDir) } +func comicOutputDir(outputRoot, slug string) string { + root := orDefault(outputRoot, ".") + if filepath.Base(filepath.Clean(root)) == "comics" { + return filepath.Join(root, slug) + } + return filepath.Join(root, "comics", slug) +} + var _ StoryRunner = (*Runner)(nil) func (r *Runner) handleNarration(ctx context.Context, storyText, titleSlug, dir string) error { diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 4f6021d..4a3f51a 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -95,7 +95,7 @@ func TestRenderPromptFallsBackToEmbeddedTemplate(t *testing.T) { if err != nil { t.Fatalf("RenderPrompt() error = %v", err) } - if !strings.Contains(got, "Напиши история с дължина около 250 думи на български") { + if !strings.Contains(got, "Write a story of about 250 words in български") { t.Fatalf("RenderPrompt() = %q, want embedded story prompt", got) } } -- cgit v1.2.3