From 430a7461e6282e305d3256b080efae60a5d522a0 Mon Sep 17 00:00:00 2001 From: Andrew-71 Date: Sat, 18 May 2024 16:15:20 +0300 Subject: [PATCH] Move to embedded dirs --- CHANGELOG.md | 14 ++++++++++++++ Dockerfile | 5 +---- README.md | 4 ++-- TODO.md | 2 ++ config.go | 2 +- i18n.go | 33 +++++++++++++++++---------------- i18n/en.json | 1 + i18n/ru.json | 1 + info.go | 4 ++-- pages/base.html | 2 +- public/favicon-512.png | Bin 0 -> 2622 bytes public/favicon.ico | Bin 894 -> 894 bytes public/manifest.json | 2 +- public/themes/sans.css | 30 ++++++++++++++++++++++++++++++ routes.go | 37 ++++++++++++++++++++++++------------- serve.go | 4 ++-- 16 files changed, 99 insertions(+), 42 deletions(-) create mode 100644 public/favicon-512.png create mode 100644 public/themes/sans.css diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a25246..6300925 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,20 @@ # Changelog This file keeps track of changes in more human-readable fashion +## v1.0.0 +This release includes several **breaking** changes +* Made a new favicon +* English is now used as a fallback language, making incomplete translations somewhat usable +* Added a link to the bottom of the page in day list, for when you need to get to footer but been using the app for months... +* `pages`, `public` and `i18n` directories now use embed.FS + * Running plain executable is now a somewhat valid option. + * A problem with this is that languages and themes are now harder to add. I will think about what to do about that, maybe some kind of `custom.css` file. + I might also be open to GitHub pull requests adding **some** languages (German and French could be nice starting points, I have friends studying them) +* Added a new "sans" theme + * Light blue accent colour + * Comic Sans MS for *everything* + * sorry + ## v0.6.0 * Replaced config reload with edit in info (api method still available, config reloads on save) * Bug fixes diff --git a/Dockerfile b/Dockerfile index f2eabc7..617b51d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,10 +15,7 @@ WORKDIR / # Bring over the executable COPY --from=build-stage /hibiscus /hibiscus -# Copy files -COPY public public/ -COPY pages pages/ -COPY i18n i18n/ +# Data dirs VOLUME /data VOLUME /config diff --git a/README.md b/README.md index d4a3352..a3b8ab5 100644 --- a/README.md +++ b/README.md @@ -50,8 +50,8 @@ password=admin # Your password port=7101 # What port to run on (probably leave on 7101 if using docker) timezone=Local # IANA Time zone database identifier ("UTC", Local", "Europe/Moscow" etc.), Defaults to Local if can't parse. grace_period=0s # Time after a new day begins, but before the switch to next day's file. e.g. 2h30m - files will change at 2:30am -language=en # ISO-639 language code (pre-installed - en, ru) -theme=default # Picked theme (pre-installed - default, gruvbox, high-contrast) +language=en # ISO-639 language code (available - en, ru) +theme=default # Picked theme (available - default, high-contrast, lavender, gruvbox, sans) title=🌺 Hibiscus.txt # The text in the header log_to_file=false # Whether to write logs to a file log_file=config/log.txt # Where to store the log file if it is enabled diff --git a/TODO.md b/TODO.md index f85d679..d35fb47 100644 --- a/TODO.md +++ b/TODO.md @@ -1,6 +1,8 @@ # TODO List of things to add to this project +* Forward/backward buttons for days + ## v1.0.0 * a logo so I can enable PWA (and look cool) * Versioned containers via `ghcr.io` or `dockerhub`, diff --git a/config.go b/config.go index db21472..08b4871 100644 --- a/config.go +++ b/config.go @@ -144,7 +144,7 @@ func (c *Config) Reload() error { } slog.Debug("reloaded config", "config", c) - return LoadLanguage(c.Language) // Load selected language + return SetLanguage(c.Language) // Load selected language } // Read gets raw contents from ConfigFile diff --git a/i18n.go b/i18n.go index 2088b55..f819c65 100644 --- a/i18n.go +++ b/i18n.go @@ -1,32 +1,33 @@ package main import ( + "embed" "encoding/json" - "errors" "log/slog" - "os" ) +//go:embed i18n +var I18n embed.FS var Translations = map[string]string{} -// LoadLanguage loads a json file for selected language into the Translations map -func LoadLanguage(language string) error { - filename := "i18n/" + language + ".json" - - if _, err := os.Stat(filename); errors.Is(err, os.ErrNotExist) { - return err +// SetLanguage loads a json file for selected language into the Translations map, with english language as a fallback +func SetLanguage(language string) error { + loadLanguage := func(language string) error { + filename := "i18n/" + language + ".json" + fileContents, err := I18n.ReadFile(filename) + if err != nil { + slog.Error("error reading language file", + "error", err, + "file", filename) + return err + } + return json.Unmarshal(fileContents, &Translations) } - - fileContents, err := os.ReadFile(filename) + err := loadLanguage("en") // Load english as fallback language if err != nil { - slog.Error("error reading file", - "error", err, - "file", filename) return err } - - err = json.Unmarshal(fileContents, &Translations) - return err + return loadLanguage(language) } // TranslatableText attempts to match an id to a string in current language diff --git a/i18n/en.json b/i18n/en.json index 9181009..2a33873 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -16,6 +16,7 @@ "button.notes": "New note", "prompt.notes": "Note name", "noscript.notes": "/notes/", + "prompt.days": "To the bottom", "info.version": "Version", "info.version.link": "source and changelog", diff --git a/i18n/ru.json b/i18n/ru.json index 0084368..f244ec6 100644 --- a/i18n/ru.json +++ b/i18n/ru.json @@ -16,6 +16,7 @@ "button.notes": "Новая Π·Π°ΠΌΠ΅Ρ‚ΠΊΠ°", "prompt.notes": "НазваниС Π·Π°ΠΌΠ΅Ρ‚ΠΊΠΈ", "noscript.notes": "/notes/<Π½Π°Π·Π²Π°Π½ΠΈΠ΅>", + "prompt.days": "Π’Π½ΠΈΠ·", "info.version": "ВСрсия", "info.version.link": "исходный ΠΊΠΎΠ΄", diff --git a/info.go b/info.go index 30841c5..a910d2b 100644 --- a/info.go +++ b/info.go @@ -6,7 +6,7 @@ import ( "net/http" ) -var infoTemplate = template.Must(template.New("").Funcs(templateFuncs).ParseFiles("./pages/base.html", "./pages/info.html")) +var infoTemplate = template.Must(template.New("").Funcs(templateFuncs).ParseFS(Pages, "pages/base.html", "pages/info.html")) type AppInfo struct { Version string @@ -15,7 +15,7 @@ type AppInfo struct { // Info contains app information var Info = AppInfo{ - Version: "0.6.1", + Version: "1.0.0", SourceLink: "https://git.a71.su/Andrew71/hibiscus", } diff --git a/pages/base.html b/pages/base.html index 84e7144..280ff4d 100644 --- a/pages/base.html +++ b/pages/base.html @@ -34,7 +34,7 @@ {{end}} {{define "footer"}} -