From 2f7f1b38029e67c20dacf0ef4eb1c10a9d1b9aff Mon Sep 17 00:00:00 2001 From: Liam Date: Sat, 27 Apr 2024 23:01:16 -0400 Subject: [PATCH] Remove static paths --- lib/philomena_web.ex | 2 +- lib/philomena_web/templates/error/show.html.slime | 4 ++-- .../templates/image/_image_target.html.slime | 2 +- lib/philomena_web/templates/layout/app.html.slime | 10 +++++----- .../templates/layout/two_factor.html.slime | 4 ++-- .../templates/setting/edit.html.slime | 2 +- lib/philomena_web/views/error_view.ex | 4 ++-- lib/philomena_web/views/layout_view.ex | 15 ++++----------- lib/philomena_web/views/setting_view.ex | 8 ++++---- 9 files changed, 22 insertions(+), 29 deletions(-) diff --git a/lib/philomena_web.ex b/lib/philomena_web.ex index 4a8fbcb8..f7234480 100644 --- a/lib/philomena_web.ex +++ b/lib/philomena_web.ex @@ -17,7 +17,7 @@ defmodule PhilomenaWeb do and import those modules here. """ - def static_paths, do: ~w(assets images favicon.ico favicon.svg robots.txt) + def static_paths, do: ~w(assets favicon.ico favicon.svg robots.txt) def controller do quote do diff --git a/lib/philomena_web/templates/error/show.html.slime b/lib/philomena_web/templates/error/show.html.slime index c0256043..a48ae8f3 100644 --- a/lib/philomena_web/templates/error/show.html.slime +++ b/lib/philomena_web/templates/error/show.html.slime @@ -8,8 +8,8 @@ html lang="en" title => @status | - Philomena - link rel="stylesheet" href=stylesheet_path(@conn, nil) - link rel="stylesheet" href=dark_stylesheet_path(@conn) media="(prefers-color-scheme: dark)" + link rel="stylesheet" href=stylesheet_path(nil) + link rel="stylesheet" href=dark_stylesheet_path() media="(prefers-color-scheme: dark)" link rel="icon" href="/favicon.ico" type="image/x-icon" link rel="icon" href="/favicon.svg" type="image/svg+xml" diff --git a/lib/philomena_web/templates/image/_image_target.html.slime b/lib/philomena_web/templates/image/_image_target.html.slime index 45315404..3443c74a 100644 --- a/lib/philomena_web/templates/image/_image_target.html.slime +++ b/lib/philomena_web/templates/image/_image_target.html.slime @@ -6,7 +6,7 @@ strong = link("This image is blocked by your current filter - click here to display it anyway", to: "#", data: [click_unfilter: @image.id]) p - = img_tag(Routes.static_path(PhilomenaWeb.Endpoint, "/images/tagblocked.svg"), width: 250, height: 250, data: [click_unfilter: @image.id]) + = img_tag(static_path(@conn, "/images/tagblocked.svg"), width: 250, height: 250, data: [click_unfilter: @image.id]) span.filter-explanation =< link("your current filter", to: Routes.filter_path(@conn, :show, @conn.assigns.current_filter), class: "filter-link") ' . diff --git a/lib/philomena_web/templates/layout/app.html.slime b/lib/philomena_web/templates/layout/app.html.slime index e86528eb..29013972 100644 --- a/lib/philomena_web/templates/layout/app.html.slime +++ b/lib/philomena_web/templates/layout/app.html.slime @@ -10,11 +10,11 @@ html lang="en" ' - Derpibooru - else ' Derpibooru - link rel="stylesheet" href=stylesheet_path(@conn, @current_user) + link rel="stylesheet" href=stylesheet_path(@current_user) = if is_nil(@current_user) do - link rel="stylesheet" href=dark_stylesheet_path(@conn) media="(prefers-color-scheme: dark)" - link rel="icon" href="/favicon.ico" type="image/x-icon" - link rel="icon" href="/favicon.svg" type="image/svg+xml" + link rel="stylesheet" href=dark_stylesheet_path() media="(prefers-color-scheme: dark)" + link rel="icon" href=~p"/favicon.ico" type="image/x-icon" + link rel="icon" href=~p"/favicon.svg" type="image/svg+xml" meta name="generator" content="philomena" meta name="theme-color" content="#618fc3" meta name="format-detection" content="telephone=no" @@ -24,7 +24,7 @@ html lang="en" script type="module" src="http://localhost:5173/@vite/client" script type="module" src="http://localhost:5173/js/app.js" - else - script type="text/javascript" src=Routes.static_path(@conn, "/js/app.js") async="async" + script type="text/javascript" src=~p"/js/app.js" async="async" = render PhilomenaWeb.LayoutView, "_opengraph.html", assigns body data-theme=theme_name(@current_user) data-vite-reload=to_string(vite_reload?()) = render PhilomenaWeb.LayoutView, "_burger.html", assigns diff --git a/lib/philomena_web/templates/layout/two_factor.html.slime b/lib/philomena_web/templates/layout/two_factor.html.slime index 2d2fc4bb..416a8732 100644 --- a/lib/philomena_web/templates/layout/two_factor.html.slime +++ b/lib/philomena_web/templates/layout/two_factor.html.slime @@ -6,8 +6,8 @@ html lang="en" = viewport_meta_tag(@conn) title Two Factor Authentication - Derpibooru - link rel="stylesheet" href=stylesheet_path(@conn, nil) - link rel="stylesheet" href=dark_stylesheet_path(@conn) media="(prefers-color-scheme: dark)" + link rel="stylesheet" href=stylesheet_path(nil) + link rel="stylesheet" href=dark_stylesheet_path() media="(prefers-color-scheme: dark)" link rel="icon" href="/favicon.ico" type="image/x-icon" link rel="icon" href="/favicon.svg" type="image/svg+xml" diff --git a/lib/philomena_web/templates/setting/edit.html.slime b/lib/philomena_web/templates/setting/edit.html.slime index 92e13038..2809de42 100644 --- a/lib/philomena_web/templates/setting/edit.html.slime +++ b/lib/philomena_web/templates/setting/edit.html.slime @@ -79,7 +79,7 @@ h1 Content Settings ' For 1080p monitors, try 24. .field => label f, :theme - => select f, :theme, theme_options(@conn), class: "input" + => select f, :theme, theme_options(), class: "input" = error_tag f, :theme .fieldlabel: i Preview themes by selecting one from the dropdown. Saving sets the currently selected theme. .field diff --git a/lib/philomena_web/views/error_view.ex b/lib/philomena_web/views/error_view.ex index 8bf8c1d0..9e1d8566 100644 --- a/lib/philomena_web/views/error_view.ex +++ b/lib/philomena_web/views/error_view.ex @@ -3,8 +3,8 @@ defmodule PhilomenaWeb.ErrorView do import PhilomenaWeb.LayoutView, only: [ - stylesheet_path: 2, - dark_stylesheet_path: 1, + stylesheet_path: 1, + dark_stylesheet_path: 0, viewport_meta_tag: 1 ] diff --git a/lib/philomena_web/views/layout_view.ex b/lib/philomena_web/views/layout_view.ex index fe338f09..b9c2210b 100644 --- a/lib/philomena_web/views/layout_view.ex +++ b/lib/philomena_web/views/layout_view.ex @@ -69,17 +69,10 @@ defmodule PhilomenaWeb.LayoutView do Config.get(:footer) end - def stylesheet_path(conn, %{theme: "dark"}), - do: Routes.static_path(conn, "/css/dark.css") - - def stylesheet_path(conn, %{theme: "red"}), - do: Routes.static_path(conn, "/css/red.css") - - def stylesheet_path(conn, _user), - do: Routes.static_path(conn, "/css/default.css") - - def dark_stylesheet_path(conn), - do: Routes.static_path(conn, "/css/dark.css") + def stylesheet_path(%{theme: "dark"}), do: ~p"/css/dark.css" + def stylesheet_path(%{theme: "red"}), do: ~p"/css/red.css" + def stylesheet_path(_user), do: ~p"/css/default.css" + def dark_stylesheet_path, do: ~p"/css/dark.css" def theme_name(%{theme: theme}), do: theme def theme_name(_user), do: "default" diff --git a/lib/philomena_web/views/setting_view.ex b/lib/philomena_web/views/setting_view.ex index df313385..ac08b4fc 100644 --- a/lib/philomena_web/views/setting_view.ex +++ b/lib/philomena_web/views/setting_view.ex @@ -1,15 +1,15 @@ defmodule PhilomenaWeb.SettingView do use PhilomenaWeb, :view - def theme_options(conn) do + def theme_options do [ [ key: "Default", value: "default", - data: [theme_path: Routes.static_path(conn, "/css/default.css")] + data: [theme_path: ~p"/css/default.css"] ], - [key: "Dark", value: "dark", data: [theme_path: Routes.static_path(conn, "/css/dark.css")]], - [key: "Red", value: "red", data: [theme_path: Routes.static_path(conn, "/css/red.css")]] + [key: "Dark", value: "dark", data: [theme_path: ~p"/css/dark.css"]], + [key: "Red", value: "red", data: [theme_path: ~p"/css/red.css"]] ] end