Implement and display headlines in interface
This commit is contained in:
parent
abd7fc6bef
commit
8c95782eff
13 changed files with 85 additions and 58 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Reference in a new issue