diff --git a/assets/js/app.js b/assets/js/app.js index acd0e4d4c..3e344c2aa 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -1,5 +1,4 @@ import "./polyfills/closest" -import "./apply-theme" import 'abortcontroller-polyfill/dist/polyfill-patch-fetch' import Alpine from 'alpinejs' import "./liveview/live_socket" diff --git a/assets/js/apply-theme.js b/assets/js/apply-theme.js deleted file mode 100644 index f715f5580..000000000 --- a/assets/js/apply-theme.js +++ /dev/null @@ -1,37 +0,0 @@ -var pref = document.currentScript.dataset.pref; - -function reapplyTheme() { - var userPref = pref || "system"; - var mediaPref = window.matchMedia('(prefers-color-scheme: dark)').matches; - var htmlRef = document.querySelector('html'); - var hcaptchaRefs = document.getElementsByClassName('h-captcha'); - - htmlRef.classList.remove('dark'); - for (let i = 0; i < hcaptchaRefs.length; i++) { - hcaptchaRefs[i].dataset.theme = "light"; - } - - switch (userPref) { - case "dark": - htmlRef.classList.add('dark'); - for (let i = 0; i < hcaptchaRefs.length; i++) { - hcaptchaRefs[i].dataset.theme = "dark"; - } - break; - case "system": - if (mediaPref) { - htmlRef.classList.add('dark'); - for (let i = 0; i < hcaptchaRefs.length; i++) { - hcaptchaRefs[i].dataset.theme = "dark"; - } - } - break; - } -} - -reapplyTheme(); -window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', reapplyTheme); - -window.onload = function() { - reapplyTheme(); -}; diff --git a/lib/plausible_web/components/layout.ex b/lib/plausible_web/components/layout.ex new file mode 100644 index 000000000..48b1e84de --- /dev/null +++ b/lib/plausible_web/components/layout.ex @@ -0,0 +1,36 @@ +defmodule PlausibleWeb.Components.Layout do + @moduledoc false + + use Phoenix.Component + + def theme_script(assigns) do + ~H""" + + """ + end + + defp current_theme(nil), do: "system" + defp current_theme(user), do: user.theme +end diff --git a/lib/plausible_web/templates/layout/app.html.eex b/lib/plausible_web/templates/layout/app.html.eex deleted file mode 100644 index 81c5bc9ec..000000000 --- a/lib/plausible_web/templates/layout/app.html.eex +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - <%= if @conn.assigns[:connect_live_socket] do %> - - - <% end %> - - "> - - <%= assigns[:title] || "Plausible · Simple, privacy-friendly alternative to Google Analytics" %> - "/> - <%= render("_tracking.html", assigns) %> - - <%= if @conn.assigns[:background], do: "background-color: #{@conn.assigns[:background]}" %>"> - <%= if !@conn.assigns[:embedded] do %> - <%= render("_header.html", assigns) %> - <%= render("_notice.html", assigns) %> - <% end %> - -
- <%= Map.get(assigns, :inner_layout) || @inner_content %> -
- - <%= if @conn.assigns[:embedded] do %> -
- - <% else %> - <%= render("_footer.html", assigns) %> - <% end %> - - <%= if @conn.assigns[:load_dashboard_js] do %> - - <% end %> - - diff --git a/lib/plausible_web/templates/layout/app.html.heex b/lib/plausible_web/templates/layout/app.html.heex new file mode 100644 index 000000000..19caf15f0 --- /dev/null +++ b/lib/plausible_web/templates/layout/app.html.heex @@ -0,0 +1,64 @@ + + + + + + + + <%= if assigns[:connect_live_socket] do %> + + + <% end %> + + + + + <%= assigns[:title] || + "Plausible · Simple, privacy-friendly alternative to Google Analytics" %> + + + <%= render("_tracking.html", assigns) %> + + + <%= if !assigns[:embedded] do %> + <%= render("_header.html", assigns) %> + <%= render("_notice.html", assigns) %> + <% end %> + +
+ <%= Map.get(assigns, :inner_layout) || @inner_content %> +
+ + + + <%= if assigns[:embedded] do %> +
+ + <% else %> + <%= render("_footer.html", assigns) %> + <% end %> + + <%= if assigns[:load_dashboard_js] do %> + + <% end %> + + diff --git a/lib/plausible_web/templates/layout/focus.html.eex b/lib/plausible_web/templates/layout/focus.html.eex deleted file mode 100644 index b28e83c53..000000000 --- a/lib/plausible_web/templates/layout/focus.html.eex +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - <%= if @conn.assigns[:connect_live_socket] do %> - - - <% end %> - "> - <%= assigns[:title] || "Plausible · Web analytics" %> - "/> - <%= render("_tracking.html", assigns) %> - - -
- - <%= img_tag(PlausibleWeb.Router.Helpers.static_path(@conn, "/images/icon/plausible_logo_dark.png"), class: "hidden dark:inline", style: "height: 2.5rem;", alt: "Plausible logo") %> - <%= img_tag(PlausibleWeb.Router.Helpers.static_path(@conn, "/images/icon/plausible_logo.png"), class: "inline dark:hidden", style: "height: 2.5rem;", alt: "Plausible logo")%> - -
- - <%= if assigns[:flash] do %> - <%= render("_flash.html", assigns) %> - <% end %> - <%= @inner_content %> - - -

- © <%= DateTime.utc_now().year() %> Plausible Analytics. All rights reserved. -

- - - - diff --git a/lib/plausible_web/templates/layout/focus.html.heex b/lib/plausible_web/templates/layout/focus.html.heex new file mode 100644 index 000000000..16f90460a --- /dev/null +++ b/lib/plausible_web/templates/layout/focus.html.heex @@ -0,0 +1,58 @@ + + + + + + + + + <%= if assigns[:connect_live_socket] do %> + + + <% end %> + + <%= assigns[:title] || "Plausible · Web analytics" %> + + <%= render("_tracking.html", assigns) %> + + +
+ + <%= img_tag( + PlausibleWeb.Router.Helpers.static_path(@conn, "/images/icon/plausible_logo_dark.png"), + class: "hidden dark:inline", + style: "height: 2.5rem;", + alt: "Plausible logo" + ) %> + <%= img_tag( + PlausibleWeb.Router.Helpers.static_path(@conn, "/images/icon/plausible_logo.png"), + class: "inline dark:hidden", + style: "height: 2.5rem;", + alt: "Plausible logo" + ) %> + +
+ + <%= if assigns[:flash] do %> + <%= render("_flash.html", assigns) %> + <% end %> + <%= @inner_content %> + +

+ © <%= DateTime.utc_now().year() %> Plausible Analytics. All rights reserved. +

+ + + + + +