Implement and display headlines in interface

This commit is contained in:
nemunaire 2018-12-02 11:43:24 +01:00
parent abd7fc6bef
commit 8c95782eff
13 changed files with 85 additions and 58 deletions

View file

@ -59,6 +59,11 @@ func SyncExercices(i Importer, theme fic.Theme) []string {
if err != nil {
errs = append(errs, fmt.Sprintf("%q: overview.txt: %s", edir, err))
}
ovrvw := strings.Split(overview, "\n")
headline := ovrvw[0]
if len(ovrvw) > 1 {
overview = strings.Join(ovrvw[1:], "\n")
}
statement, err := getFileContent(i, path.Join(theme.Path, edir, "statement.txt"))
if err != nil {
@ -111,18 +116,20 @@ func SyncExercices(i Importer, theme fic.Theme) []string {
// Markdown pre-formating
statement = string(blackfriday.Run([]byte(statement)))
overview = string(blackfriday.Run([]byte(overview)))
headline = string(blackfriday.Run([]byte(headline)))
e, err := theme.GetExerciceByTitle(ename)
if err != nil {
if e, err = theme.AddExercice(ename, fic.ToURLid(ename), path.Join(theme.Path, edir), statement, overview, depend, gain, videoURI); err != nil {
if e, err = theme.AddExercice(ename, fic.ToURLid(ename), path.Join(theme.Path, edir), statement, overview, headline, depend, gain, videoURI); err != nil {
errs = append(errs, fmt.Sprintf("%q: error on exercice add: %s", edir, err))
continue
}
} else if e.Title != ename || e.URLId == "" || e.Statement != statement || e.Overview != overview || e.Gain != gain || e.VideoURI != videoURI {
} else if e.Title != ename || e.URLId == "" || e.Statement != statement || e.Overview != overview || e.Headline != headline || e.Gain != gain || e.VideoURI != videoURI {
e.Title = ename
e.URLId = fic.ToURLid(ename)
e.Statement = statement
e.Overview = overview
e.Headline = headline
e.Gain = gain
e.VideoURI = videoURI
if _, err := e.Update(); err != nil {

View file

@ -62,6 +62,7 @@ func SyncThemes(i Importer) []string {
for _, tdir := range themes {
var authors []string
var intro string
var headline string
var image string
var theme fic.Theme
var tname string
@ -78,10 +79,19 @@ func SyncThemes(i Importer) []string {
continue
} else if intro, err = getFileContent(i, path.Join(tdir, "overview.txt")); err != nil {
errs = append(errs, fmt.Sprintf("%q: unable to get theme's overview: %s", tname, err))
} else if theme, err = fic.GetThemeByName(tname); err != nil {
if _, err := fic.CreateTheme(tname, fic.ToURLid(tname), tdir, strings.Join(authors, ", "), intro, image); err != nil {
errs = append(errs, fmt.Sprintf("%q: an error occurs during add: %s", tdir, err))
continue
} else {
// Split headline from intro
ovrvw := strings.Split(intro, "\n")
headline = ovrvw[0]
if len(ovrvw) > 1 {
intro = strings.Join(ovrvw[1:], "\n")
}
if theme, err = fic.GetThemeByName(tname); err != nil {
if _, err := fic.CreateTheme(tname, fic.ToURLid(tname), tdir, strings.Join(authors, ", "), intro, headline, image); err != nil {
errs = append(errs, fmt.Sprintf("%q: an error occurs during add: %s", tdir, err))
continue
}
}
}
@ -90,6 +100,7 @@ func SyncThemes(i Importer) []string {
// Format overview (markdown)
intro = string(blackfriday.Run([]byte(intro)))
headline = string(blackfriday.Run([]byte(headline)))
if i.exists(path.Join(tdir, "heading.jpg")) {
image = path.Join(tdir, "heading.jpg")
@ -108,10 +119,11 @@ func SyncThemes(i Importer) []string {
}
}
if theme.Name != tname || theme.Authors != authors_str || theme.Intro != intro || theme.Image != image {
if theme.Name != tname || theme.Authors != authors_str || theme.Headline != headline || theme.Intro != intro || theme.Image != image {
theme.Name = tname
theme.Authors = authors_str
theme.Intro = intro
theme.Headline = headline
theme.Image = image
theme.Path = tdir
if _, err := theme.Update(); err != nil {