sync: Exercice headline can be in a dedicated file
This commit is contained in:
parent
7cc076b31e
commit
ec3f818c30
@ -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
|
// Texts to format using Markdown
|
||||||
if i.Exists(path.Join(epath, "overview.txt")) {
|
if i.Exists(path.Join(epath, "overview.txt")) {
|
||||||
e.Overview, err = GetFileContent(i, 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
|
var buf bytes.Buffer
|
||||||
err := goldmark.Convert([]byte(strings.Split(e.Overview, "\n")[0]), &buf)
|
if e.Headline == "" {
|
||||||
if err != nil {
|
err := goldmark.Convert([]byte(strings.Split(e.Overview, "\n")[0]), &buf)
|
||||||
errs = append(errs, NewExerciceError(e, fmt.Errorf("overview.md: an error occurs during markdown formating of the headline: %w", err), theme))
|
if err != nil {
|
||||||
} else {
|
errs = append(errs, NewExerciceError(e, fmt.Errorf("overview.md: an error occurs during markdown formating of the headline: %w", err), theme))
|
||||||
e.Headline = string(buf.Bytes())
|
} else {
|
||||||
|
e.Headline = string(buf.Bytes())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if e.Overview, err = ProcessMarkdown(i, e.Overview, epath); err != nil {
|
if e.Overview, err = ProcessMarkdown(i, e.Overview, epath); err != nil {
|
||||||
|
@ -140,8 +140,25 @@ func BuildTheme(i Importer, tdir string) (th *fic.Theme, exceptions *CheckExcept
|
|||||||
th.Authors = strings.Join(authors, ", ")
|
th.Authors = strings.Join(authors, ", ")
|
||||||
}
|
}
|
||||||
|
|
||||||
var intro string
|
|
||||||
var err error
|
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")) {
|
if i.Exists(path.Join(tdir, "overview.txt")) {
|
||||||
intro, err = GetFileContent(i, path.Join(tdir, "overview.txt"))
|
intro, err = GetFileContent(i, path.Join(tdir, "overview.txt"))
|
||||||
} else if i.Exists(path.Join(tdir, "overview.md")) {
|
} 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
|
// Split headline from intro
|
||||||
ovrvw := strings.Split(fixnbsp(intro), "\n")
|
if th.Headline == "" {
|
||||||
th.Headline = ovrvw[0]
|
ovrvw := strings.Split(fixnbsp(intro), "\n")
|
||||||
if len(ovrvw) > 1 {
|
th.Headline = ovrvw[0]
|
||||||
intro = strings.Join(ovrvw[1:], "\n")
|
if len(ovrvw) > 1 {
|
||||||
|
intro = strings.Join(ovrvw[1:], "\n")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Format overview (markdown)
|
// Format overview (markdown)
|
||||||
|
Loading…
Reference in New Issue
Block a user