diff options
| author | Anhgelus Morhtuuzh <william@herges.fr> | 2025-12-14 17:50:33 +0000 |
|---|---|---|
| committer | Anhgelus Morhtuuzh <william@herges.fr> | 2025-12-14 17:50:33 +0000 |
| commit | 3312977ebeff03edc5b1bc1a2f815cad6a1ba7b8 (patch) | |
| tree | 419617345dba2da3d0b666d5993964ce75904efa /backend/config.go | |
| parent | 8edad5f9aee4625384485ad07180da751858839c (diff) | |
| parent | 0c0c6fb6df755d8f53d353e8b941e22a6c474b60 (diff) | |
Merge pull request '[Feat] Custom replace' (#3) from feat/custom-replace into main
Reviewed-on: https://git.anhgelus.world/anhgelus/small-web/pulls/3
Diffstat (limited to 'backend/config.go')
| -rw-r--r-- | backend/config.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/backend/config.go b/backend/config.go index 44b2033..e009b8a 100644 --- a/backend/config.go +++ b/backend/config.go @@ -5,6 +5,7 @@ import ( "log/slog" "os" + "git.anhgelus.world/anhgelus/small-web/markdown" "github.com/pelletier/go-toml/v2" ) @@ -22,6 +23,11 @@ type Logo struct { Favicon string `toml:"favicon"` } +type Replacer struct { + Symbol string `toml:"symbol"` + Replace string `tomle:"replace"` +} + type Config struct { Domain string `toml:"domain"` Name string `toml:"name"` @@ -37,6 +43,8 @@ type Config struct { Links []Link `toml:"links"` Logo Logo `toml:"logo"` + + Replacers []Replacer `toml:"replacers"` } func (c *Config) DefaultValues() { @@ -66,8 +74,11 @@ func (c *Config) DefaultValues() { c.RootFolder = "data" c.PublicFolder = "public" c.Quotes = []string{"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do."} + c.Replacers = []Replacer{{"~", " "}} } +var defaultMarkdownOption markdown.Option + func LoadConfig(path string) (*Config, bool) { b, err := os.ReadFile(path) var config Config @@ -97,5 +108,14 @@ func LoadConfig(path string) (*Config, bool) { slog.Error("unmarshalling config file", "error", err) return nil, false } + defaultMarkdownOption.ImageSource = getStatic + defaultMarkdownOption.Replaces = make(map[rune]string, len(config.Replacers)) + for _, r := range config.Replacers { + if len(r.Symbol) != 1 { + slog.Error("invalid symbol in config", "symbol", r.Symbol) + return nil, false + } + defaultMarkdownOption.Replaces[[]rune(r.Symbol)[0]] = r.Replace + } return &config, true } |
