feat(config): supports toml for custom pages

This commit is contained in:
Anhgelus Morhtuuzh 2025-03-03 11:20:29 +01:00
parent 383b67669a
commit aa5a93e978
No known key found for this signature in database
GPG key ID: CAD341EFA92DDDE5

View file

@ -2,7 +2,9 @@ package main
import (
"encoding/json"
"errors"
"fmt"
"github.com/BurntSushi/toml"
"github.com/anhgelus/golatt"
"html/template"
"log/slog"
@ -125,7 +127,13 @@ func (c *Config) LoadCustomPages() ([]*CustomPage, error) {
return nil, err
}
var p CustomPage
if strings.HasSuffix(cp, ".json") {
err = json.Unmarshal(b, &p)
} else if strings.HasSuffix(cp, ".toml") {
err = toml.Unmarshal(b, &p)
} else {
return nil, errors.New("custom page file must be .json or .toml")
}
if err != nil {
return nil, err
}