sync: Exercice headline can be in a dedicated file

This commit is contained in:
nemunaire 2023-10-13 16:04:42 +02:00
commit ec3f818c30
2 changed files with 49 additions and 10 deletions

View file

@ -151,6 +151,24 @@ func BuildExercice(i Importer, theme *fic.Theme, epath string, dmap *map[int64]*
}
}
// Process headline
if i.Exists(path.Join(epath, "headline.txt")) {
e.Headline, err = GetFileContent(i, path.Join(epath, "headline.txt"))
} else if i.Exists(path.Join(epath, "headline.md")) {
e.Headline, err = GetFileContent(i, path.Join(epath, "headline.md"))
}
if err != nil {
errs = append(errs, NewExerciceError(e, fmt.Errorf("unable to get exercice's headline: %w", err)))
}
if e.Headline != "" {
// Call checks hooks
for _, h := range hooks.mdTextHooks {
for _, err := range h("headline.md", e.Language, exceptions.GetFileExceptions("headline.md", "headline.txt")) {
errs = append(errs, NewExerciceError(e, fmt.Errorf("headline.md: %w", err)))
}
}
}
// Texts to format using Markdown
if i.Exists(path.Join(epath, "overview.txt")) {
e.Overview, err = GetFileContent(i, path.Join(epath, "overview.txt"))
@ -172,11 +190,13 @@ func BuildExercice(i Importer, theme *fic.Theme, epath string, dmap *map[int64]*
}
var buf bytes.Buffer
err := goldmark.Convert([]byte(strings.Split(e.Overview, "\n")[0]), &buf)
if err != nil {
errs = append(errs, NewExerciceError(e, fmt.Errorf("overview.md: an error occurs during markdown formating of the headline: %w", err), theme))
} else {
e.Headline = string(buf.Bytes())
if e.Headline == "" {
err := goldmark.Convert([]byte(strings.Split(e.Overview, "\n")[0]), &buf)
if err != nil {
errs = append(errs, NewExerciceError(e, fmt.Errorf("overview.md: an error occurs during markdown formating of the headline: %w", err), theme))
} else {
e.Headline = string(buf.Bytes())
}
}
if e.Overview, err = ProcessMarkdown(i, e.Overview, epath); err != nil {