diff --git a/.tangled/workflows/deploy-blog.yml b/.tangled/workflows/deploy-blog.yml index e15e6694..5f9e2a59 100644 --- a/.tangled/workflows/deploy-blog.yml +++ b/.tangled/workflows/deploy-blog.yml @@ -23,7 +23,7 @@ steps: command: | ./dolly.out -template appview/pages/templates/fragments/dolly/logo.html -output appview/pages/static/logos/dolly.png -size 180x180 ./dolly.out -template appview/pages/templates/fragments/dolly/logo.html -output appview/pages/static/logos/dolly.ico -size 48x48 - ./dolly.out -template appview/pages/templates/fragments/dolly/logo.html -output appview/pages/static/logos/dolly.svg -color currentColor + ./dolly.out -template appview/pages/templates/fragments/dolly/logo.html -output appview/pages/static/logos/dolly.svg -color currentColor -favicon - name: generate css command: | diff --git a/appview/pages/pages.go b/appview/pages/pages.go index afc62229..691fc07a 100644 --- a/appview/pages/pages.go +++ b/appview/pages/pages.go @@ -298,6 +298,9 @@ func (p *Pages) executeProfile(name string, w io.Writer, params any) error { type DollyParams struct { Classes string FillColor string + // Favicon embeds a prefers-color-scheme style block so the SVG + // adapts to dark mode when used as a standalone favicon document. + Favicon bool } func (p *Pages) Dolly(w io.Writer, params DollyParams) error { @@ -306,7 +309,7 @@ func (p *Pages) Dolly(w io.Writer, params DollyParams) error { func (p *Pages) Favicon(w io.Writer) error { return p.Dolly(w, DollyParams{ - Classes: "text-black dark:text-white", + Favicon: true, }) } diff --git a/appview/pages/templates/fragments/dolly/logo.html b/appview/pages/templates/fragments/dolly/logo.html index c450d400..d9a7a57b 100644 --- a/appview/pages/templates/fragments/dolly/logo.html +++ b/appview/pages/templates/fragments/dolly/logo.html @@ -4,6 +4,19 @@ viewBox="0 0 32 32" fill="{{ or .FillColor "currentColor" }}" xmlns="http://www.w3.org/2000/svg"> + {{ if .Favicon }} + + {{ end }} {{ end }} diff --git a/cmd/dolly/main.go b/cmd/dolly/main.go index 094a1dc0..e1a851f7 100644 --- a/cmd/dolly/main.go +++ b/cmd/dolly/main.go @@ -26,12 +26,14 @@ func main() { fillColor string output string templatePath string + favicon bool ) flag.StringVar(&templatePath, "template", "", "Path to dolly go-html template") flag.StringVar(&size, "size", "512x512", "Output size in format WIDTHxHEIGHT (e.g., 512x512)") flag.StringVar(&fillColor, "color", "#000000", "Fill color in hex format (e.g., #FF5733)") flag.StringVar(&output, "output", "dolly.svg", "Output file path (format detected from extension: .svg, .png, or .ico)") + flag.BoolVar(&favicon, "favicon", false, "Embed a prefers-color-scheme style block so the SVG reacts to dark mode (SVG output only)") flag.Parse() if templatePath == "" { @@ -65,7 +67,12 @@ func main() { os.Exit(1) } - svgData, err := dolly(string(tpl), fillColor) + if favicon && format != "svg" { + fmt.Fprintf(os.Stderr, "-favicon is only supported for .svg output\n") + os.Exit(1) + } + + svgData, err := dolly(string(tpl), fillColor, favicon) if err != nil { fmt.Fprintf(os.Stderr, "Error generating SVG: %v\n", err) os.Exit(1) @@ -97,7 +104,7 @@ func main() { fmt.Printf("Successfully generated %s (%dx%d)\n", output, width, height) } -func dolly(tplString, hexColor string) ([]byte, error) { +func dolly(tplString, hexColor string, favicon bool) ([]byte, error) { tpl, err := template.New("dolly").Parse(tplString) if err != nil { return nil, err @@ -107,6 +114,7 @@ func dolly(tplString, hexColor string) ([]byte, error) { if err := tpl.ExecuteTemplate(&svgData, "fragments/dolly/logo", map[string]any{ "FillColor": hexColor, "Classes": "", + "Favicon": favicon, }); err != nil { return nil, err } diff --git a/localinfra/scripts/appview-static-files.sh b/localinfra/scripts/appview-static-files.sh index 5eddddd0..543ee302 100755 --- a/localinfra/scripts/appview-static-files.sh +++ b/localinfra/scripts/appview-static-files.sh @@ -41,4 +41,4 @@ cp -f "$TMP/actor-typeahead/actor-typeahead.js" "$OUT/" TEMPLATE="$REPO_ROOT/appview/pages/templates/fragments/dolly/logo.html" "$TMP/dolly" -template "$TEMPLATE" -output "$OUT/logos/dolly.png" -size 180x180 "$TMP/dolly" -template "$TEMPLATE" -output "$OUT/logos/dolly.ico" -size 48x48 -"$TMP/dolly" -template "$TEMPLATE" -output "$OUT/logos/dolly.svg" -color currentColor +"$TMP/dolly" -template "$TEMPLATE" -output "$OUT/logos/dolly.svg" -color currentColor -favicon diff --git a/nix/pkgs/appview-static-files.nix b/nix/pkgs/appview-static-files.nix index 7b1edd2f..50360611 100644 --- a/nix/pkgs/appview-static-files.nix +++ b/nix/pkgs/appview-static-files.nix @@ -32,7 +32,7 @@ runCommandLocal "appview-static-files" { ${dolly}/bin/dolly -output logos/dolly.png -size 180x180 ${dolly}/bin/dolly -output logos/dolly.ico -size 48x48 - ${dolly}/bin/dolly -output logos/dolly.svg -color currentColor + ${dolly}/bin/dolly -output logos/dolly.svg -color currentColor -favicon # tailwindcss -c $src/tailwind.config.js -i $src/input.css -o tw.css won't work # for whatever reason (produces broken css), so we are doing this instead cd ${src} && ${tailwindcss}/bin/tailwindcss -i input.css -o $out/tw.css diff --git a/nix/pkgs/docs.nix b/nix/pkgs/docs.nix index 5bcf71ee..c5084be8 100644 --- a/nix/pkgs/docs.nix +++ b/nix/pkgs/docs.nix @@ -56,7 +56,7 @@ runCommandLocal "docs" {} '' # favicons ${dolly}/bin/dolly -output $out/static/logos/dolly.png -size 180x180 ${dolly}/bin/dolly -output $out/static/logos/dolly.ico -size 48x48 - ${dolly}/bin/dolly -output $out/static/logos/dolly.svg -color currentColor + ${dolly}/bin/dolly -output $out/static/logos/dolly.svg -color currentColor -favicon # styles cd ${src} && ${tailwindcss}/bin/tailwindcss -i input.css -o $out/stylesheet.css