mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-09-23 05:16:23 -07:00
fix(anki): regenerate sentence furigana from the final sentence (#268)
This commit is contained in:
@@ -74,6 +74,10 @@ export interface NoteUpdateWorkflowDeps {
|
||||
sentenceFurigana: string,
|
||||
noteFields: Record<string, string>,
|
||||
) => string;
|
||||
generateSentenceFurigana?: (
|
||||
text: string,
|
||||
noteFields: Record<string, string>,
|
||||
) => Promise<string | null>;
|
||||
setCardTypeFields: (
|
||||
updatedFields: Record<string, string>,
|
||||
availableFieldNames: string[],
|
||||
@@ -282,7 +286,27 @@ export class NoteUpdateWorkflow {
|
||||
const existingSentenceFurigana = sentenceFuriganaField
|
||||
? noteInfo.fields[sentenceFuriganaField]?.value || ''
|
||||
: '';
|
||||
if (sentenceFuriganaField && existingSentenceFurigana && this.deps.processSentenceFurigana) {
|
||||
const sentenceChanged =
|
||||
sentenceField &&
|
||||
currentSubtitleText &&
|
||||
normalizeSubtitleContextText(currentSubtitleText) !==
|
||||
normalizeSubtitleContextText(noteInfo.fields[sentenceField]?.value ?? '');
|
||||
if (sentenceFuriganaField && sentenceChanged) {
|
||||
let furigana: string | null = null;
|
||||
try {
|
||||
furigana =
|
||||
(await this.deps.generateSentenceFurigana?.(currentSubtitleText, fields)) ?? null;
|
||||
} catch (error) {
|
||||
this.deps.logWarn('Failed to regenerate sentence furigana:', error);
|
||||
}
|
||||
// Empty furigana lets card templates fall back to the updated Sentence field.
|
||||
updatedFields[sentenceFuriganaField] = furigana ?? '';
|
||||
updatePerformed = true;
|
||||
} else if (
|
||||
sentenceFuriganaField &&
|
||||
existingSentenceFurigana &&
|
||||
this.deps.processSentenceFurigana
|
||||
) {
|
||||
const processedSentenceFurigana = this.deps.processSentenceFurigana(
|
||||
existingSentenceFurigana,
|
||||
fields,
|
||||
|
||||
Reference in New Issue
Block a user