aboutsummaryrefslogtreecommitdiff
path: root/pkg/config
diff options
context:
space:
mode:
authorGabriel A. Giovanini <mail@gabrielgio.me>2025-11-01 17:48:02 +0100
committerGabriel A. Giovanini <mail@gabrielgio.me>2025-11-01 17:49:00 +0100
commited1fc6854a634f7fcff7d1a500c40e7502031ea7 (patch)
tree6832b21ce3fcd903fb24afcd0a2fdd0bc2b9f381 /pkg/config
parentaec177b7acca580733264aa1db2a18bc154fc7b5 (diff)
downloadcerrado-ed1fc6854a634f7fcff7d1a500c40e7502031ea7.tar.gz
cerrado-ed1fc6854a634f7fcff7d1a500c40e7502031ea7.tar.bz2
cerrado-ed1fc6854a634f7fcff7d1a500c40e7502031ea7.zip
feat: Add option to configure dark/light themes
Diffstat (limited to 'pkg/config')
-rw-r--r--pkg/config/config.go38
-rw-r--r--pkg/config/config_test.go32
2 files changed, 57 insertions, 13 deletions
diff --git a/pkg/config/config.go b/pkg/config/config.go
index c00586b..ff969ec 100644
--- a/pkg/config/config.go
+++ b/pkg/config/config.go
@@ -39,6 +39,11 @@ type (
Public bool
}
+ SyntaxHighlight struct {
+ Dark string
+ Light string
+ }
+
// configuration represents file configuration.
// fields needs to be exported to cmp to work
configuration struct {
@@ -50,7 +55,7 @@ type (
Repositories []*GitRepositoryConfiguration
RootReadme string
Scans []*scan
- SyntaxHighlight string
+ SyntaxHighlight SyntaxHighlight
Hostname string
}
@@ -75,7 +80,7 @@ type (
removeSuffix bool
repositories []*GitRepositoryConfiguration
rootReadme string
- syntaxHighlight string
+ syntaxHighlight SyntaxHighlight
hostname string
}
)
@@ -129,7 +134,11 @@ func (c *ConfigurationRepository) GetOrderBy() OrderBy {
}
func (c *ConfigurationRepository) GetSyntaxHighlight() string {
- return c.syntaxHighlight
+ return c.syntaxHighlight.Light
+}
+
+func (c *ConfigurationRepository) GetSyntaxHighlightDark() string {
+ return c.syntaxHighlight.Dark
}
func (c *ConfigurationRepository) GetListenAddr() string {
@@ -371,9 +380,26 @@ func setAESKey(block scfg.Block, listenAddr *string) error {
return setString(scanDir, listenAddr)
}
-func setSyntaxHighlight(block scfg.Block, listenAddr *string) error {
- scanDir := block.Get("syntax-highlight")
- return setString(scanDir, listenAddr)
+func setSyntaxHighlight(block scfg.Block, sh *SyntaxHighlight) error {
+ shDir := block.Get("syntax-highlight")
+ if shDir == nil {
+ return nil
+ }
+
+ themes := shDir.Params
+ if len(themes) > 2 || len(themes) == 0 {
+ return errors.New("syntax-highlight must contains at most two params and at least one, light then dark theme name")
+ }
+
+ sh.Light = themes[0]
+ if len(themes) > 1 {
+ sh.Dark = themes[1]
+ } else {
+ // if dark is not set use light
+ sh.Dark = sh.Light
+ }
+
+ return nil
}
func setOrderby(block scfg.Block, orderBy *string) error {
diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go
index 31cf1c0..50744b5 100644
--- a/pkg/config/config_test.go
+++ b/pkg/config/config_test.go
@@ -48,6 +48,21 @@ scan "/srv/git" {
},
},
{
+ name: "themes",
+ config: `
+syntax-highlight light dark`,
+ expectedConfig: &configuration{
+ Scans: defaultScans(),
+ ListenAddr: defaultAddr(),
+ Hostname: defaultHostname(),
+ Repositories: []*GitRepositoryConfiguration{},
+ SyntaxHighlight: SyntaxHighlight{
+ Light: "light",
+ Dark: "dark",
+ },
+ },
+ },
+ {
name: "minimal repository",
config: `repository /srv/git/cerrado.git`,
expectedConfig: &configuration{
@@ -139,13 +154,16 @@ repository /srv/git/cerrado.git {
Path: "/srv/git",
},
},
- ListenAddr: "unix://var/run/cerrado/cerrado.sock",
- Passphrase: "$2a$14$VnB/ZcB1DUDkMnosRA6Y7.dj8h5eroslDxTeXlLwfQX/x86mh6WAq",
- AESKey: "8XHptZxSWCGs1m7QzztX5zNQ7D9NiQevVX0DaUTNMbDpRwFzoJiB0U7K6O/kqIt01jJVgzBUfiR8ES46ZLLb4w==",
- SyntaxHighlight: "monokailight",
- OrderBy: "lastcommit-desc",
- RemoveSuffix: true,
- Hostname: "https://domain.tld",
+ ListenAddr: "unix://var/run/cerrado/cerrado.sock",
+ Passphrase: "$2a$14$VnB/ZcB1DUDkMnosRA6Y7.dj8h5eroslDxTeXlLwfQX/x86mh6WAq",
+ AESKey: "8XHptZxSWCGs1m7QzztX5zNQ7D9NiQevVX0DaUTNMbDpRwFzoJiB0U7K6O/kqIt01jJVgzBUfiR8ES46ZLLb4w==",
+ SyntaxHighlight: SyntaxHighlight{
+ Light: "monokailight",
+ Dark: "monokailight",
+ },
+ OrderBy: "lastcommit-desc",
+ RemoveSuffix: true,
+ Hostname: "https://domain.tld",
Repositories: []*GitRepositoryConfiguration{
{
Name: "linux.git",