add basic theming support

pull/7/head
cblgh 2022-02-20 15:36:07 +01:00
rodzic e0426514c9
commit 98e8d74eb5
5 zmienionych plików z 38 dodań i 0 usunięć

Wyświetl plik

@ -57,6 +57,10 @@ typical workflow.
After ingesting the data with `lieu ingest`, you can also use lieu to search the
corpus in the terminal with `lieu search`.
## Theming
Tweak the `theme` values of the config, specified below.
## Config
The config file is written in [TOML](https://toml.io/en/).
@ -68,6 +72,12 @@ name = "Merveilles Webring"
url = "https://webring.xxiivv.com"
port = 10001
[theme]
# colors specified in hex (or valid css names) which determine the theme of the lieu instance
foreground = "#ffffff"
background = "#000000"
links = "#ffffff"
[data]
# the source file should contain the crawl command's output
source = "data/crawled.txt"

Wyświetl plik

@ -12,6 +12,7 @@
</style>
<link href="/assets/style.css" rel="stylesheet">
<link href="/assets/theme.css" rel="stylesheet">
<link rel="icon" href="/assets/favicon.ico">
<link rel="icon" href="/assets/logo.svg" type="image/svg+xml">

Wyświetl plik

@ -227,7 +227,23 @@ func (h RequestHandler) renderView(res http.ResponseWriter, tmpl string, view *T
}
}
func WriteTheme(config types.Config) {
theme := config.Theme
// no theme is set, use the default
if theme.Foreground == "" {
return
}
colors := fmt.Sprintf(`:root {
--primary: %s;
--secondary: %s;
--link: %s;
}\n`, theme.Foreground, theme.Background, theme.Links)
err := os.WriteFile("html/assets/theme.css", []byte(colors), 0644)
util.Check(err)
}
func Serve(config types.Config) {
WriteTheme(config)
db := database.InitDB(config.Data.Database)
handler := RequestHandler{config: config, db: db}

Wyświetl plik

@ -21,6 +21,11 @@ type Config struct {
URL string `json:url`
Port int `json:port`
} `json:general`
Theme struct {
Foreground string `json:"foreground"`
Background string `json:"background"`
Links string `json:"links"`
} `json:"theme"`
Data struct {
Source string `json:source`
Database string `json:database`

Wyświetl plik

@ -105,6 +105,12 @@ name = "Sweet Webring"
url = "https://example.com/"
port = 10001
[theme]
# colors specified in hex (or valid css names) which determine the theme of the lieu instance
foreground = "#ffffff"
background = "#000000"
links = "#ffffff"
[data]
# the source file should contain the crawl command's output
source = "data/crawled.txt"