aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <anhgelus@anhgelus.world>2025-03-03 11:18:59 +0100
committerAnhgelus Morhtuuzh <anhgelus@anhgelus.world>2025-03-03 11:18:59 +0100
commit383b67669aaddbc2f9f98b4f28718b515a2d2670 (patch)
treedbc26aee2f1aa8c96849de97364dc0a42663e29f
parent69ab8022bd8efff2cc5eec5f97af977642e297d8 (diff)
feat(cli): option to generate config file for toml or json
-rw-r--r--data.go2
-rw-r--r--main.go76
2 files changed, 74 insertions, 4 deletions
diff --git a/data.go b/data.go
index 4fcb8a7..df85090 100644
--- a/data.go
+++ b/data.go
@@ -62,7 +62,7 @@ type BackgroundColor struct {
Colors []struct {
Color string `json:"color" toml:"color"`
Position uint `json:"position" toml:"position"`
- } `json:"colors"`
+ } `json:"colors" toml:"colors"`
}
type ButtonColor struct {
diff --git a/main.go b/main.go
index 80c83d8..abe1751 100644
--- a/main.go
+++ b/main.go
@@ -20,19 +20,27 @@ var (
)
var (
- domain string
- configPath string
- dev bool
+ domain string
+ configPath string
+ dev bool
+ generateToml bool
+ generateJson bool
)
func init() {
flag.StringVar(&domain, "domain", "", "domain to use")
flag.StringVar(&configPath, "config", "", "config to use")
flag.BoolVar(&dev, "dev", false, "dev mode enabled")
+ flag.BoolVar(&generateJson, "generate-json-config", false, "generate a config example")
+ flag.BoolVar(&generateToml, "generate-toml-config", false, "generate a config example")
}
func main() {
flag.Parse()
+ if generateToml || generateJson {
+ generateConfigFile(generateToml)
+ return
+ }
if domain == "" {
domain = os.Getenv("NOW_DOMAIN")
if domain == "" {
@@ -123,3 +131,65 @@ func main() {
g.StartServer(":80")
}
}
+
+func generateConfigFile(isToml bool) {
+ cfg := Config{
+ Image: "wallpaper.webp",
+ Description: "I am a beautiful description!",
+ Person: &Person{
+ Name: "John Doe",
+ Pronouns: "any",
+ Image: "pfp.webp",
+ Tags: []*Tag{
+ {"Hello", "World", ""},
+ {"I am", "a tag", ""},
+ },
+ },
+ Color: &Color{
+ Background: &BackgroundColor{
+ Type: "linear",
+ Angle: 141,
+ Colors: []struct {
+ Color string `json:"color" toml:"color"`
+ Position uint `json:"position" toml:"position"`
+ }{
+ {"#a4a2b8", 0},
+ {"#3b3860", 40},
+ {"#0f0c2c", 80},
+ },
+ },
+ Button: &ButtonColor{
+ Text: "#4c0850",
+ TextHover: "#57145b",
+ Background: "#f399d0",
+ BackgroundHover: "#f5c0e0",
+ },
+ Text: "#fff",
+ TagHover: "#000",
+ },
+ Links: []*Link{
+ {"/foo", "Blog"},
+ {"https://www.youtube.com/@anhgelus", "YouTube"},
+ },
+ Legal: &Legal{
+ LegalInformationLink: "/bar",
+ ImagesSource: []string{
+ "Profile picture: some one on website",
+ "Background picture: another one on another website",
+ },
+ FontSource: "Name by some one on website",
+ },
+ CustomPages: []string{"custom.json"},
+ }
+ var b []byte
+ var err error
+ if isToml {
+ b, err = toml.Marshal(&cfg)
+ } else {
+ b, err = json.Marshal(&cfg)
+ }
+ if err != nil {
+ panic(err)
+ }
+ println(string(b))
+}