diff options
author | r <r@freesoftwareextremist.com> | 2019-12-26 11:25:29 +0000 |
---|---|---|
committer | r <r@freesoftwareextremist.com> | 2019-12-26 11:25:29 +0000 |
commit | 591360f2a8727e3b1f9e5f28ed3f6d983d6464b8 (patch) | |
tree | a65f4b12d04897cb7bdbf6747ba03cca29e3441c /config | |
parent | ac4ff88adb9a2526555757f8d4e65c69cafb3788 (diff) | |
download | bloat-591360f2a8727e3b1f9e5f28ed3f6d983d6464b8.tar.gz bloat-591360f2a8727e3b1f9e5f28ed3f6d983d6464b8.zip |
Add post format selection
Diffstat (limited to 'config')
-rw-r--r-- | config/config.go | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/config/config.go b/config/config.go index 17fceca..c463c91 100644 --- a/config/config.go +++ b/config/config.go @@ -6,6 +6,7 @@ import ( "io" "os" "strings" + "web/model" ) type config struct { @@ -17,6 +18,7 @@ type config struct { TemplatesGlobPattern string DatabasePath string CustomCSS string + PostFormats []model.PostFormat Logfile string } @@ -43,7 +45,13 @@ func getDefaultConfig() *config { TemplatesGlobPattern: "templates/*", DatabasePath: "database.db", CustomCSS: "", - Logfile: "", + PostFormats: []model.PostFormat{ + model.PostFormat{"Plain Text", "text/plain"}, + model.PostFormat{"HTML", "text/html"}, + model.PostFormat{"Markdown", "text/markdown"}, + model.PostFormat{"BBCode", "text/bbcode"}, + }, + Logfile: "", } } @@ -87,6 +95,25 @@ func Parse(r io.Reader) (c *config, err error) { c.DatabasePath = val case "custom_css": c.CustomCSS = val + case "post_formats": + vals := strings.Split(val, ",") + var formats []model.PostFormat + for _, v := range vals { + pair := strings.Split(v, ":") + if len(pair) != 2 { + return nil, errors.New("invalid config key " + key) + } + n := strings.TrimSpace(pair[0]) + t := strings.TrimSpace(pair[1]) + if len(n) < 1 || len(t) < 1 { + return nil, errors.New("invalid config key " + key) + } + formats = append(formats, model.PostFormat{ + Name: n, + Type: t, + }) + } + c.PostFormats = formats case "logfile": c.Logfile = val default: |