From 606f8ec3a01fc6296526bf7d8d55278d2a032a0f Mon Sep 17 00:00:00 2001 From: WeebDataHoarder Date: Sat, 3 May 2025 04:14:11 +0200 Subject: [PATCH] templates: explicitly allow overriding logo via cmdline/override in config, have bundled templates support it --- README.md | 6 +++++- cmd/go-away/main.go | 4 +++- embed/templates/challenge-anubis.gohtml | 3 ++- embed/templates/challenge-forgejo.gohtml | 3 ++- examples/config.yml | 6 ++++-- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 31a8ac4..8743644 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,11 @@ These templates are included by default: External templates for your site can be loaded specifying a full path to the `.gohtml` file. See [embed/templates/](embed/templates/) for examples to follow. -You can alter the language and strings in the templates directly from the [config.yml](#config) file if specified, or add footer links directly. +You can alter the language and strings in the templates directly from the [config.yml](examples/config.yml) file if specified, or add footer links directly. + +Some templates support themes. Specify that either via the [config.yml](examples/config.yml) file, or via `challenge-template-theme` cmdline argument. + +Most templates support overriding the logo. Specify that either via the [config.yml](examples/config.yml) file, or via `challenge-template-logo` cmdline argument. **Feel free to make any changes to existing templates or bring your own, alter any logos or styling, it's yours to adapt!** diff --git a/cmd/go-away/main.go b/cmd/go-away/main.go index 873e8cf..171d443 100644 --- a/cmd/go-away/main.go +++ b/cmd/go-away/main.go @@ -86,7 +86,8 @@ func main() { flag.StringVar(&opt.ChallengeTemplate, "challenge-template", opt.ChallengeTemplate, "name or path of the challenge template to use (anubis, forgejo)") - templateTheme := flag.String("challenge-template-theme", opt.ChallengeTemplateOverrides["Theme"], "name of the challenge template theme to use (forgejo => [forgejo-auto, forgejo-dark, forgejo-light, gitea...])") + templateTheme := flag.String("challenge-template-theme", opt.ChallengeTemplateOverrides["Theme"], "override template theme to use (forgejo => [forgejo-auto, forgejo-dark, forgejo-light, gitea...])") + templateLogo := flag.String("challenge-template-logo", opt.ChallengeTemplateOverrides["Logo"], "override template logo to use") basePath := flag.String("path", "/.well-known/."+internalCmdName, "base path where to expose go-away package onto, challenges will be served from here") @@ -136,6 +137,7 @@ func main() { // preload missing settings opt.ChallengeTemplateOverrides["Theme"] = *templateTheme + opt.ChallengeTemplateOverrides["Logo"] = *templateLogo // load overrides if *settingsFile != "" { diff --git a/embed/templates/challenge-anubis.gohtml b/embed/templates/challenge-anubis.gohtml index d2791da..d29a63a 100644 --- a/embed/templates/challenge-anubis.gohtml +++ b/embed/templates/challenge-anubis.gohtml @@ -1,4 +1,5 @@ +{{$logo := print .Path "/assets/static/logo.png?cacheBust=" .Random }}{{ if .Logo }}{{$logo = .Logo}}{{ end }} {{ .Title }} @@ -25,7 +26,7 @@ {{if .Challenge }}

{{ .Strings.Get "status_loading_challenge" }} {{ .Challenge }}...

diff --git a/embed/templates/challenge-forgejo.gohtml b/embed/templates/challenge-forgejo.gohtml index 824157d..a43252c 100644 --- a/embed/templates/challenge-forgejo.gohtml +++ b/embed/templates/challenge-forgejo.gohtml @@ -1,5 +1,6 @@ {{$theme := "forgejo-auto"}}{{ if .Theme }}{{$theme = .Theme}}{{ end }} +{{$logo := "/assets/img/logo.png"}}{{ if .Logo }}{{$logo = .Logo}}{{ end }} @@ -48,7 +49,7 @@
- +

diff --git a/examples/config.yml b/examples/config.yml index 49a7ded..e064c12 100644 --- a/examples/config.yml +++ b/examples/config.yml @@ -40,8 +40,8 @@ links: # HTML Template to use for challenge or error pages # External templates can be included by providing a disk path # Bundled templates: -# anubis: An Anubis-like template with no configuration parameters -# forgejo: Looks like native Forgejo. Includes logos and resources from your instance. Supports Theme. +# anubis: An Anubis-like template with no configuration parameters. Supports Logo. +# forgejo: Looks like native Forgejo. Includes logos and resources from your instance. Supports Theme, Logo. # #challenge-template: "anubis" @@ -49,6 +49,8 @@ links: challenge-template-overrides: # Set template theme if supported #Theme: "forgejo-auto" + # Set logo on template if supported + #Logo: "/my/custom/logo/path.png" # Advanced backend configuration # Backends setup via cmdline will be added here