diff --git a/admin/sync/exercices.go b/admin/sync/exercices.go index 42661178..7aeebef5 100644 --- a/admin/sync/exercices.go +++ b/admin/sync/exercices.go @@ -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 { diff --git a/admin/sync/themes.go b/admin/sync/themes.go index a4ab9bda..06a86b0d 100644 --- a/admin/sync/themes.go +++ b/admin/sync/themes.go @@ -140,8 +140,25 @@ func BuildTheme(i Importer, tdir string) (th *fic.Theme, exceptions *CheckExcept th.Authors = strings.Join(authors, ", ") } - var intro string var err error + if i.Exists(path.Join(tdir, "headline.txt")) { + th.Headline, err = GetFileContent(i, path.Join(tdir, "headline.txt")) + } else if i.Exists(path.Join(tdir, "headline.md")) { + th.Headline, err = GetFileContent(i, path.Join(tdir, "headline.md")) + } + if err != nil { + errs = append(errs, NewThemeError(th, fmt.Errorf("unable to get theme's headline: %w", err))) + } + if th.Headline != "" { + // Call checks hooks + for _, h := range hooks.mdTextHooks { + for _, err := range h("headline.md", th.Language, exceptions.GetFileExceptions("headline.md", "headline.txt")) { + errs = append(errs, NewThemeError(th, fmt.Errorf("headline.md: %w", err))) + } + } + } + + var intro string if i.Exists(path.Join(tdir, "overview.txt")) { intro, err = GetFileContent(i, path.Join(tdir, "overview.txt")) } else if i.Exists(path.Join(tdir, "overview.md")) { @@ -160,10 +177,12 @@ func BuildTheme(i Importer, tdir string) (th *fic.Theme, exceptions *CheckExcept } // Split headline from intro - ovrvw := strings.Split(fixnbsp(intro), "\n") - th.Headline = ovrvw[0] - if len(ovrvw) > 1 { - intro = strings.Join(ovrvw[1:], "\n") + if th.Headline == "" { + ovrvw := strings.Split(fixnbsp(intro), "\n") + th.Headline = ovrvw[0] + if len(ovrvw) > 1 { + intro = strings.Join(ovrvw[1:], "\n") + } } // Format overview (markdown)