From 4b09efa9fd72f05ed9f5a0cf26883ab16e2ada1b Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Fri, 9 Dec 2022 16:07:06 +0100 Subject: [PATCH] sync: Handle finished.md as alternative to finished.txt --- admin/sync/exercices.go | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/admin/sync/exercices.go b/admin/sync/exercices.go index de68f8ae..5e4cc852 100644 --- a/admin/sync/exercices.go +++ b/admin/sync/exercices.go @@ -184,19 +184,21 @@ func BuildExercice(i Importer, theme *fic.Theme, epath string, dmap *map[int64]* if i.exists(path.Join(epath, "finished.txt")) { e.Finished, err = GetFileContent(i, path.Join(epath, "finished.txt")) - if err != nil { - errs = append(errs, NewExerciceError(e, fmt.Errorf("finished.txt: %w", err), theme)) - } else { - // Call checks hooks - for _, h := range hooks.mdTextHooks { - for _, err := range h(e.Finished, exceptions.GetFileExceptions("finished.md", "finished.txt")) { - errs = append(errs, NewExerciceError(e, fmt.Errorf("finished.md: %w", err))) - } + } else if i.exists(path.Join(epath, "finished.md")) { + e.Finished, err = GetFileContent(i, path.Join(epath, "finished.md")) + } + if err != nil { + errs = append(errs, NewExerciceError(e, fmt.Errorf("finished.md: %w", err), theme)) + } else if len(e.Finished) > 0 { + // Call checks hooks + for _, h := range hooks.mdTextHooks { + for _, err := range h(e.Finished, exceptions.GetFileExceptions("finished.md", "finished.txt")) { + errs = append(errs, NewExerciceError(e, fmt.Errorf("finished.md: %w", err))) } + } - if e.Finished, err = ProcessMarkdown(i, e.Finished, epath); err != nil { - errs = append(errs, NewExerciceError(e, fmt.Errorf("finished.txt: an error occurs during markdown formating: %w", err), theme)) - } + if e.Finished, err = ProcessMarkdown(i, e.Finished, epath); err != nil { + errs = append(errs, NewExerciceError(e, fmt.Errorf("finished.md: an error occurs during markdown formating: %w", err), theme)) } }