package main import ( "encoding/json" "path/filepath" tpl "lamium/template" util "lamium/util" ) type ( // A Config defines settings for album generation. Config struct { HTMLDir string `json:"htmlDir"` IndexHTML string `json:"indexHTML"` IndexTitle string `json:"indexTitle"` IndexType string `json:"indexType"` ThemeDir string `json:"themeDir"` Sets []tpl.Set `json:"sets"` } ) var ( // Example configuration. sampleConfig = Config{ HTMLDir: "public_html", IndexHTML: "index.html", IndexTitle: "My Album", IndexType: "text", ThemeDir: "themes/nettle", Sets: []tpl.Set{ { Name: "set1", ImageDir: "set1", IndexHTML: "index.html", Title: "Set 1", SortOrder: "modTimeDesc", CSSClassIframe: "frame", CSSClassLink: "link", CSSClassThumb: "thumb", LightboxOn: true, LinkType: "page", ThumbDir: "thumbs", ThumbWidth: 200, ThumbHeight: 200, ThumbPct: 0, ThumbClip: "square", ThumbUnifyMode: "height", }, }, } // Error messages. configErr = struct { configNotLoaded string jsonNotSaved string }{ configNotLoaded: "Error: config could not be loaded:", jsonNotSaved: "Error: JSON config could not be saved:", } ) // genConfig outputs an example configuration file at path. func genConfig(path string) { conf, jsonErr := json.MarshalIndent(sampleConfig, "", " ") if !util.HasError(jsonErr, configErr.jsonNotSaved+" "+path, true) { util.MakeDir(filepath.Dir(path)) util.SaveFile(path, string(conf), true) } } // loadConfig returns a *Config interface of settings after reading // the configuration file at path. func loadConfig(path string) *Config { contents := util.LoadFile(path, true) conf := &Config{} json.Unmarshal([]byte(contents), &conf) return conf }