diff --git a/assets/build.js b/assets/build.js index a1d8d11..b993d1a 100644 --- a/assets/build.js +++ b/assets/build.js @@ -14,7 +14,7 @@ const plugins = [ ] let opts = { - entryPoints: ['js/app.js'], + entryPoints: ['js/app.js', 'js/public.js'], bundle: true, target: 'es2017', outdir: '../priv/static/assets', diff --git a/assets/css/app.css b/assets/css/app.css index c526f3e..95f241d 100644 --- a/assets/css/app.css +++ b/assets/css/app.css @@ -54,6 +54,10 @@ @apply underline decoration-2 decoration-theme-primary; } +.prose img { + @apply rounded; +} + /* Set width and color for identity icons */ a[rel] svg { width: 1em; diff --git a/assets/css/lightbox.css b/assets/css/lightbox.css index c2754f9..8366b1a 100644 --- a/assets/css/lightbox.css +++ b/assets/css/lightbox.css @@ -35,3 +35,8 @@ background-size: contain; } +.lightbox span img { + width: 75%; + margin: 0 auto; +} + diff --git a/assets/js/public.js b/assets/js/public.js new file mode 100644 index 0000000..3af215d --- /dev/null +++ b/assets/js/public.js @@ -0,0 +1,17 @@ +import lolight from "../vendor/lolight" + +lolight("pre code") + +document + .querySelector("#dark-mode-toggle") + .addEventListener("click", (e) => { + e.preventDefault() + const data = document.documentElement.dataset + if (data["mode"] && data["mode"] == "dark") { + delete data["mode"] + window.localStorage.removeItem("theme") + } else { + data["mode"] = "dark" + window.localStorage.setItem("theme", "dark") + } + }) \ No newline at end of file diff --git a/lib/chiya/channels.ex b/lib/chiya/channels.ex index 6205e43..c06e0db 100644 --- a/lib/chiya/channels.ex +++ b/lib/chiya/channels.ex @@ -9,9 +9,13 @@ defmodule Chiya.Channels do alias Chiya.Notes.Note @preloads [:notes] - @public_preloads [notes: (from n in Note, - where: not is_nil(n.published_at), - order_by: [desc: n.published_at])] + @public_preloads [ + notes: + from(n in Note, + where: not is_nil(n.published_at), + order_by: [desc: n.published_at] + ) + ] @doc """ Returns the list of channels. @@ -56,7 +60,7 @@ defmodule Chiya.Channels do Gets a single channel by its slug with all associated entities preloaded. """ def get_channel_by_slug!(slug), do: Repo.get_by!(Channel, slug: slug) - + @doc """ Creates a channel. diff --git a/lib/chiya/channels/channel.ex b/lib/chiya/channels/channel.ex index 0500e86..5d18d16 100644 --- a/lib/chiya/channels/channel.ex +++ b/lib/chiya/channels/channel.ex @@ -12,7 +12,7 @@ defmodule Chiya.Channels.Channel do many_to_many :notes, Chiya.Notes.Note, join_through: "channels_notes", join_keys: [channel: :id, note: :id] - + timestamps() end diff --git a/lib/chiya/notes.ex b/lib/chiya/notes.ex index ab8b783..571c4c6 100644 --- a/lib/chiya/notes.ex +++ b/lib/chiya/notes.ex @@ -21,7 +21,7 @@ defmodule Chiya.Notes do """ def list_notes do Note - |> order_by([n], [desc: n.updated_at, desc: n.published_at]) + |> order_by([n], desc: n.updated_at, desc: n.published_at) |> Repo.all() |> Repo.preload(@preloads) end @@ -67,9 +67,8 @@ defmodule Chiya.Notes do """ def get_note_preloaded!(id), do: Repo.get!(Note, id) |> preload_note() - - def get_note_by_slug_preloaded!(slug), do: Repo.get_by!(Note, slug: slug) |> preload_note() + def get_note_by_slug_preloaded!(slug), do: Repo.get_by!(Note, slug: slug) |> preload_note() @doc """ Creates a note. diff --git a/lib/chiya_web.ex b/lib/chiya_web.ex index ab785de..330ed59 100644 --- a/lib/chiya_web.ex +++ b/lib/chiya_web.ex @@ -17,7 +17,8 @@ defmodule ChiyaWeb do those modules here. """ - def static_paths, do: ~w(assets fonts images favicon favicon.ico robots.txt browserconfig.xml site.webmanifest) + def static_paths, + do: ~w(assets fonts images favicon favicon.ico robots.txt browserconfig.xml site.webmanifest) def router do quote do @@ -56,6 +57,9 @@ defmodule ChiyaWeb do use Phoenix.LiveView, layout: {ChiyaWeb.Layouts, :app} + # Import admin components + import ChiyaWeb.AdminComponents + unquote(html_helpers()) end end @@ -78,6 +82,25 @@ defmodule ChiyaWeb do # Include general helpers for rendering HTML unquote(html_helpers()) + + # Import admin components + import ChiyaWeb.AdminComponents + end + end + + def html_public do + quote do + use Phoenix.Component + + # Import convenience functions from controllers + import Phoenix.Controller, + only: [get_csrf_token: 0, view_module: 1, view_template: 1] + + # Include general helpers for rendering HTML + unquote(html_helpers()) + + # Import public components + import ChiyaWeb.PublicComponents end end @@ -93,10 +116,9 @@ defmodule ChiyaWeb do alias Phoenix.LiveView.JS # Custom functions - import ChiyaWeb.AdminComponents import ChiyaWeb.Format, only: [from_now: 1, pretty_date: 1] alias ChiyaWeb.Markdown - + # Routes generation with the ~p sigil unquote(verified_routes()) end diff --git a/lib/chiya_web/components/admin_components.ex b/lib/chiya_web/components/admin_components.ex index cd71075..add47c0 100644 --- a/lib/chiya_web/components/admin_components.ex +++ b/lib/chiya_web/components/admin_components.ex @@ -1,6 +1,6 @@ defmodule ChiyaWeb.AdminComponents do + use Phoenix.Component - use Phoenix.Component use Phoenix.VerifiedRoutes, endpoint: ChiyaWeb.Endpoint, router: ChiyaWeb.Router, @@ -8,6 +8,15 @@ defmodule ChiyaWeb.AdminComponents do import ChiyaWeb.CoreComponents + @doc """ + Renders a horizontal line + """ + def line(assigns) do + ~H""" +