sync: import heading theme image
This commit is contained in:
parent
0effdbcf5e
commit
3a0c892148
4 changed files with 24 additions and 4 deletions
|
|
@ -57,6 +57,7 @@ func SyncThemes(i Importer) []string {
|
|||
for _, tdir := range themes {
|
||||
var authors []string
|
||||
var intro string
|
||||
var image string
|
||||
var theme fic.Theme
|
||||
var tname string
|
||||
|
||||
|
|
@ -73,7 +74,7 @@ func SyncThemes(i Importer) []string {
|
|||
} 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); 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
|
||||
}
|
||||
|
|
@ -85,10 +86,28 @@ func SyncThemes(i Importer) []string {
|
|||
// Format overview (markdown)
|
||||
intro = string(blackfriday.Run([]byte(intro)))
|
||||
|
||||
if theme.Name != tname || theme.Authors != authors_str || theme.Intro != intro {
|
||||
if i.exists(path.Join(tdir, "heading.jpg")) {
|
||||
image = path.Join(tdir, "heading.jpg")
|
||||
} else if i.exists(path.Join(tdir, "heading.png")) {
|
||||
image = path.Join(tdir, "heading.png")
|
||||
}
|
||||
|
||||
if len(image) > 0 {
|
||||
if _, err := i.importFile(image,
|
||||
func(filePath string, origin string) (interface{}, error) {
|
||||
image = strings.TrimPrefix(filePath, fic.FilesDir)
|
||||
return nil, nil
|
||||
}); err != nil {
|
||||
errs = append(errs, fmt.Sprintf("%q: unable to import heading image: %s", tdir, err))
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if theme.Name != tname || theme.Authors != authors_str || theme.Intro != intro || theme.Image != image {
|
||||
theme.Name = tname
|
||||
theme.Authors = authors_str
|
||||
theme.Intro = intro
|
||||
theme.Image = image
|
||||
theme.Path = tdir
|
||||
if _, err := theme.Update(); err != nil {
|
||||
errs = append(errs, fmt.Sprintf("%q: an error occurs during update: %s", tdir, err))
|
||||
|
|
|
|||
Reference in a new issue