diff options
| author | Paul Buetow <paul@buetow.org> | 2025-08-02 15:08:33 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-08-02 15:08:33 +0300 |
| commit | 310ad64d1ad0b6e30a7dfaab0344dd78cabae463 (patch) | |
| tree | 41d51e7ab49f2bbbb0bb0a13faf9678cccaf34c3 /internal/processor/processor.go | |
| parent | 18a475657cbc7b2ff8ee537b082eeef25e9bf619 (diff) | |
also export reverse cards via apkg
Diffstat (limited to 'internal/processor/processor.go')
| -rw-r--r-- | internal/processor/processor.go | 47 |
1 files changed, 38 insertions, 9 deletions
diff --git a/internal/processor/processor.go b/internal/processor/processor.go index 1e1c20f..4bb6b0a 100644 --- a/internal/processor/processor.go +++ b/internal/processor/processor.go @@ -415,16 +415,45 @@ func (p *Processor) GenerateAnkiFile() (string, error) { AudioFormat: p.flags.AudioFormat, }) - // Generate cards from output directory - if err := gen.GenerateFromDirectory(p.flags.OutputDir); err != nil { - return "", fmt.Errorf("failed to generate cards: %w", err) - } - - // Add translations to cards + // Use the translation cache as the source of truth for cards translations := p.translationCache.GetAll() - for i := range gen.GetCards() { - if translation, ok := translations[gen.GetCards()[i].Bulgarian]; ok { - gen.GetCards()[i].Translation = translation + if len(translations) == 0 { + fmt.Println(" No translations found in cache, generating cards from directory...") + // Fallback to old method if cache is empty but files might exist + if err := gen.GenerateFromDirectory(p.flags.OutputDir); err != nil { + return "", fmt.Errorf("failed to generate cards from directory: %w", err) + } + } else { + fmt.Printf(" Generating cards from %d translations in cache...\n", len(translations)) + for bulgarian, english := range translations { + card := anki.Card{ + Bulgarian: bulgarian, + Translation: english, + } + + // Find associated media files in the output directory + wordDir := p.findCardDirectory(bulgarian) + if wordDir != "" { + // Look for audio file + audioFile := filepath.Join(wordDir, fmt.Sprintf("audio.%s", p.flags.AudioFormat)) + if _, err := os.Stat(audioFile); err == nil { + card.AudioFile = audioFile + } + + // Look for image file + imageFile := filepath.Join(wordDir, "image.jpg") // Assuming jpg, adjust if needed + if _, err := os.Stat(imageFile); err == nil { + card.ImageFile = imageFile + } + + // Load phonetic information as notes + phoneticFile := filepath.Join(wordDir, "phonetic.txt") + if data, err := os.ReadFile(phoneticFile); err == nil { + notes := strings.TrimSpace(string(data)) + card.Notes = strings.ReplaceAll(notes, "\n", "<br>") + } + } + gen.AddCard(card) } } |
