feat(config): supports toml for custom pages
This commit is contained in:
parent
383b67669a
commit
aa5a93e978
1 changed files with 9 additions and 1 deletions
10
data.go
10
data.go
|
@ -2,7 +2,9 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/BurntSushi/toml"
|
||||||
"github.com/anhgelus/golatt"
|
"github.com/anhgelus/golatt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
|
@ -125,7 +127,13 @@ func (c *Config) LoadCustomPages() ([]*CustomPage, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var p CustomPage
|
var p CustomPage
|
||||||
err = json.Unmarshal(b, &p)
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue