templates: explicitly allow overriding logo via cmdline/override in config, have bundled templates support it

This commit is contained in:
WeebDataHoarder
2025-05-03 04:14:11 +02:00
parent 1ea19c5a6c
commit 606f8ec3a0
5 changed files with 16 additions and 6 deletions

View File

@@ -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. 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!** **Feel free to make any changes to existing templates or bring your own, alter any logos or styling, it's yours to adapt!**

View File

@@ -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)") 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") 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 // preload missing settings
opt.ChallengeTemplateOverrides["Theme"] = *templateTheme opt.ChallengeTemplateOverrides["Theme"] = *templateTheme
opt.ChallengeTemplateOverrides["Logo"] = *templateLogo
// load overrides // load overrides
if *settingsFile != "" { if *settingsFile != "" {

View File

@@ -1,4 +1,5 @@
<!DOCTYPE html> <!DOCTYPE html>
{{$logo := print .Path "/assets/static/logo.png?cacheBust=" .Random }}{{ if .Logo }}{{$logo = .Logo}}{{ end }}
<html> <html>
<head> <head>
<title>{{ .Title }}</title> <title>{{ .Title }}</title>
@@ -25,7 +26,7 @@
<img <img
id="image" id="image"
style="width:100%;max-width:256px;" style="width:100%;max-width:256px;"
src="{{ .Path }}/assets/static/logo.png?cacheBust={{ .Random }}" src="{{ $logo }}"
/> />
{{if .Challenge }} {{if .Challenge }}
<p id="status">{{ .Strings.Get "status_loading_challenge" }} <em>{{ .Challenge }}</em>...</p> <p id="status">{{ .Strings.Get "status_loading_challenge" }} <em>{{ .Challenge }}</em>...</p>

View File

@@ -1,5 +1,6 @@
<!DOCTYPE html> <!DOCTYPE html>
{{$theme := "forgejo-auto"}}{{ if .Theme }}{{$theme = .Theme}}{{ end }} {{$theme := "forgejo-auto"}}{{ if .Theme }}{{$theme = .Theme}}{{ end }}
{{$logo := "/assets/img/logo.png"}}{{ if .Logo }}{{$logo = .Logo}}{{ end }}
<html lang="en-US" data-theme="{{ $theme }}"> <html lang="en-US" data-theme="{{ $theme }}">
<head> <head>
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
@@ -48,7 +49,7 @@
<div class="ui stackable middle very relaxed page grid"> <div class="ui stackable middle very relaxed page grid">
<div class="sixteen wide center aligned centered column"> <div class="sixteen wide center aligned centered column">
<div> <div>
<img class="logo" id="image" src="/assets/img/logo.png" /> <img class="logo" id="image" src="{{ $logo }}" />
</div> </div>
<div class="hero"> <div class="hero">
<h2 class="ui icon header title" id="title"> <h2 class="ui icon header title" id="title">

View File

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