sync: Exercice headline can be in a dedicated file

This commit is contained in:
nemunaire 2023-10-13 16:04:42 +02:00
parent 7cc076b31e
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,12 +190,14 @@ func BuildExercice(i Importer, theme *fic.Theme, epath string, dmap *map[int64]*
}
var buf bytes.Buffer
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 {
errs = append(errs, NewExerciceError(e, fmt.Errorf("overview.md: an error occurs during markdown formating: %w", err), theme))

View File

@ -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,11 +177,13 @@ func BuildTheme(i Importer, tdir string) (th *fic.Theme, exceptions *CheckExcept
}
// Split headline from intro
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)
th.Intro, err = ProcessMarkdown(i, intro, tdir)