sync: search theme's label in a title.txt file, fallback on dirname
This commit is contained in:
parent
6f7bd3b785
commit
4e01377a29
2 changed files with 14 additions and 2 deletions
|
@ -57,7 +57,9 @@ func BuildTheme(i Importer, tdir string) (th *fic.Theme, errs []string) {
|
||||||
th.Path = tdir
|
th.Path = tdir
|
||||||
|
|
||||||
// Extract theme's label
|
// Extract theme's label
|
||||||
if f := strings.Index(tdir, "-"); f >= 0 {
|
if tname, err := getFileContent(i, path.Join(tdir, "title.txt")); err == nil {
|
||||||
|
th.Name = fixnbsp(tname)
|
||||||
|
} else if f := strings.Index(tdir, "-"); f >= 0 {
|
||||||
th.Name = fixnbsp(tdir[f+1:])
|
th.Name = fixnbsp(tdir[f+1:])
|
||||||
} else {
|
} else {
|
||||||
th.Name = fixnbsp(tdir)
|
th.Name = fixnbsp(tdir)
|
||||||
|
@ -130,7 +132,7 @@ func SyncThemes(i Importer) []string {
|
||||||
}
|
}
|
||||||
|
|
||||||
var theme fic.Theme
|
var theme fic.Theme
|
||||||
if theme, err = fic.GetThemeByName(btheme.Name); err != nil {
|
if theme, err = fic.GetThemeByPath(btheme.Path); err != nil {
|
||||||
if _, err := fic.CreateTheme(*btheme); err != nil {
|
if _, err := fic.CreateTheme(*btheme); err != nil {
|
||||||
errs = append(errs, fmt.Sprintf("%q: an error occurs during add: %s", tdir, err))
|
errs = append(errs, fmt.Sprintf("%q: an error occurs during add: %s", tdir, err))
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -62,6 +62,16 @@ func GetThemeByName(name string) (Theme, error) {
|
||||||
return t, nil
|
return t, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetThemeByPath retrieves a Theme from its dirname
|
||||||
|
func GetThemeByPath(dirname string) (Theme, error) {
|
||||||
|
var t Theme
|
||||||
|
if err := DBQueryRow("SELECT id_theme, name, url_id, path, authors, intro, headline, image FROM themes WHERE path=?", dirname).Scan(&t.Id, &t.Name, &t.URLId, &t.Path, &t.Authors, &t.Intro, &t.Headline, &t.Image); err != nil {
|
||||||
|
return t, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return t, nil
|
||||||
|
}
|
||||||
|
|
||||||
// CreateTheme creates and fills a new struct Theme and registers it into the database.
|
// CreateTheme creates and fills a new struct Theme and registers it into the database.
|
||||||
func CreateTheme(theme Theme) (Theme, error) {
|
func CreateTheme(theme Theme) (Theme, error) {
|
||||||
if res, err := DBExec("INSERT INTO themes (name, url_id, authors, path, intro, headline, image) VALUES (?, ?, ?, ?, ?, ?, ?)", theme.Name, theme.URLId, theme.Authors, theme.Path, theme.Intro, theme.Headline, theme.Image); err != nil {
|
if res, err := DBExec("INSERT INTO themes (name, url_id, authors, path, intro, headline, image) VALUES (?, ?, ?, ?, ?, ?, ?)", theme.Name, theme.URLId, theme.Authors, theme.Path, theme.Intro, theme.Headline, theme.Image); err != nil {
|
||||||
|
|
Reference in a new issue