feat: override static_paths and add custom head view for theme injection

This commit is contained in:
2025-11-09 09:19:10 +01:00
parent 6fd7c32669
commit dce10fb971
2 changed files with 19 additions and 7 deletions

View File

@@ -8,7 +8,7 @@ services:
volumes:
- asciinema_data:/var/opt/asciinema
- ./custom.exs:/opt/app/etc/custom.exs:ro
- ./theme:/opt/app/priv/static/theme/custom:ro
- ./theme:/opt/app/priv/static/theme:ro
environment:
SECRET_KEY_BASE: ${ASCIINEMA_SECRET_KEY}
URL_HOST: ${ASCIINEMA_TRAEFIK_HOST}

View File

@@ -16,9 +16,21 @@ config :asciinema, Asciinema.Emails.Mailer,
versions: [:"tlsv1.2", :"tlsv1.3"]
]
# Try to inject custom head HTML (if supported by asciinema)
config :asciinema, AsciinemaWeb.Endpoint,
extra_head_html: """
<link rel="stylesheet" href="/theme/custom/custom.css">
<link rel="icon" type="image/svg+xml" href="/theme/custom/favicon.svg">
"""
# Override static_paths to include our theme directory
# This allows serving custom CSS and favicon from /theme path
defmodule AsciinemaWeb do
def static_paths, do: ~w(assets fonts images js favicon.ico robots.txt theme)
end
# Define a custom layout view that injects our theme CSS and favicon
defmodule AsciinemaWeb.CustomLayoutView do
def head(_conn, _assigns) do
Phoenix.HTML.raw("""
<link rel="stylesheet" href="/theme/custom.css">
<link rel="icon" type="image/svg+xml" href="/theme/favicon.svg">
""")
end
end
# Override the layout view to use our custom head function
config :asciinema, AsciinemaWeb.LayoutView, head: &AsciinemaWeb.CustomLayoutView.head/2