From 58f5bd364cbc1c9ac37b270a8e0351a8ac152d62 Mon Sep 17 00:00:00 2001 From: Inhji Date: Sat, 9 Sep 2023 16:08:30 +0200 Subject: [PATCH] burst of energy --- assets/css/app.css | 21 +++- assets/css/tokyo-night-dark.css | 117 ++++++++++++++++++ config/dev.exs | 2 +- lib/chiya/notes.ex | 13 ++ lib/chiya/notes/note.ex | 4 + .../components/layouts/root_public.html.heex | 2 +- lib/chiya_web/components/public_components.ex | 7 +- lib/chiya_web/controllers/page_controller.ex | 19 ++- lib/chiya_web/controllers/page_html.ex | 2 +- .../controllers/page_html/bookmarks.html.heex | 1 - .../controllers/page_html/home.html.heex | 6 +- .../controllers/page_html/note.html.heex | 10 +- .../controllers/page_html/note_list.html.heex | 6 +- .../page_html/note_list_default.html.heex | 7 +- .../controllers/page_html/tag.html.heex | 2 +- .../controllers/page_html/tag_bar.html.heex | 7 +- .../controllers/page_html/tag_list.html.heex | 4 +- .../controllers/page_html/wiki.html.heex | 2 +- .../plugs/plug_micropub/handler_behaviour.ex | 2 +- mix.exs | 2 + mix.lock | 4 + test/chiya_web/indie/micropub_test.exs | 2 +- 22 files changed, 202 insertions(+), 40 deletions(-) create mode 100644 assets/css/tokyo-night-dark.css diff --git a/assets/css/app.css b/assets/css/app.css index a86fef4..b07c5c9 100644 --- a/assets/css/app.css +++ b/assets/css/app.css @@ -4,6 +4,7 @@ @import "./lightbox.css"; @import "./tablesort.css"; +@import "./tokyo-night-dark.css"; /* The base layer is for things like reset rules or default styles applied to plain HTML elements. @@ -110,11 +111,29 @@ .dot { @apply before:content-['ยท'] } + + .pagination { + @apply flex justify-between mt-6; + + & .pagination-previous, & .pagination-next { + @apply block py-2 px-3 bg-slate-700 text-white rounded; + } + + & .pagination-previous.disabled, & .pagination-next.disabled { + @apply bg-slate-500; + } + + & .pagination-list { + @apply hidden; + } + } } /* The utilities layer is for small, single-purpose classes that should always take precedence over any other styles. */ @layer utilities { - + .hljs { + background: transparent !important; + } } \ No newline at end of file diff --git a/assets/css/tokyo-night-dark.css b/assets/css/tokyo-night-dark.css new file mode 100644 index 0000000..05625cf --- /dev/null +++ b/assets/css/tokyo-night-dark.css @@ -0,0 +1,117 @@ +/*! + Theme: Tokyo-night-Dark + origin: https://github.com/enkia/tokyo-night-vscode-theme + Description: Original highlight.js style + Author: (c) Henri Vandersleyen + License: see project LICENSE + Touched: 2022 +*/ + +/* Comment */ +.hljs-meta, +.hljs-comment { + color: #565f89; +} + +/* Red */ +/*INFO: This keyword, HTML elements, Regex group symbol, CSS units, Terminal Red */ +.hljs-tag, +.hljs-doctag, +.hljs-selector-id, +.hljs-selector-class, +.hljs-regexp, +.hljs-template-tag, +.hljs-selector-pseudo, +.hljs-selector-attr, +.hljs-variable.language_, +.hljs-deletion { + color: #f7768e; +} + +/*Orange */ +/*INFO: Number and Boolean constants, Language support constants */ +.hljs-variable, +.hljs-template-variable, +.hljs-number, +.hljs-literal, +.hljs-type, +.hljs-params, +.hljs-link { + color: #ff9e64; +} + + +/* Yellow */ +/* INFO: Function parameters, Regex character sets, Terminal Yellow */ +.hljs-built_in, +.hljs-attribute { + color: #e0af68; +} +/* cyan */ +/* INFO: Language support functions, CSS HTML elements */ +.hljs-selector-tag { + color: #2ac3de; +} + +/* light blue */ +/* INFO: Object properties, Regex quantifiers and flags, Markdown headings, Terminal Cyan, Markdown code, Import/export keywords */ +.hljs-keyword, + .hljs-title.function_, +.hljs-title, +.hljs-title.class_, +.hljs-title.class_.inherited__, +.hljs-subst, +.hljs-property {color: #7dcfff;} + +/*Green*/ +/* INFO: Object literal keys, Markdown links, Terminal Green */ +.hljs-selector-tag { color: #73daca;} + + +/*Green(er) */ +/* INFO: Strings, CSS class names */ +.hljs-quote, +.hljs-string, +.hljs-symbol, +.hljs-bullet, +.hljs-addition { + color: #9ece6a; +} + +/* Blue */ +/* INFO: Function names, CSS property names, Terminal Blue */ +.hljs-code, +.hljs-formula, +.hljs-section { + color: #7aa2f7; +} + + + +/* Magenta */ +/*INFO: Control Keywords, Storage Types, Regex symbols and operators, HTML Attributes, Terminal Magenta */ +.hljs-name, +.hljs-keyword, +.hljs-operator, +.hljs-keyword, +.hljs-char.escape_, +.hljs-attr { + color: #bb9af7; +} + +/* white*/ +/* INFO: Variables, Class names, Terminal White */ +.hljs-punctuation {color: #c0caf5} + +.hljs { + background: #1a1b26; + color: #9aa5ce; +} + +.hljs-emphasis { + font-style: italic; +} + +.hljs-strong { + font-weight: bold; +} diff --git a/config/dev.exs b/config/dev.exs index 7424eb9..730edde 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -59,7 +59,7 @@ config :chiya, ChiyaWeb.Endpoint, ~r"priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$", ~r"priv/gettext/.*(po)$", ~r"lib/chiya_web/(controllers|live|components)/.*(ex|heex)$" - ], + ] ] # Enable dev routes for dashboard and mailbox diff --git a/lib/chiya/notes.ex b/lib/chiya/notes.ex index 0b14264..f8b9b70 100644 --- a/lib/chiya/notes.ex +++ b/lib/chiya/notes.ex @@ -39,6 +39,19 @@ defmodule Chiya.Notes do |> Repo.preload(@preloads) end + def list_home_notes(channel, params) do + q = + list_notes_by_channel_query(channel) + |> where([n], not is_nil(n.published_at)) + |> order_by([n], desc: n.updated_at, desc: n.published_at) + |> preload(^@preloads) + + Flop.validate_and_run(q, params, + for: Chiya.Notes.Note, + repo: Chiya.Repo + ) + end + def list_notes_by_channel(%Chiya.Channels.Channel{} = channel) do list_notes_by_channel_query(channel) |> order_by([n], desc: n.updated_at, desc: n.published_at) diff --git a/lib/chiya/notes/note.ex b/lib/chiya/notes/note.ex index 8603899..9db2e01 100644 --- a/lib/chiya/notes/note.ex +++ b/lib/chiya/notes/note.ex @@ -11,6 +11,10 @@ defmodule Chiya.Notes.Note do @reserved_slugs ~w(user admin dev api) @note_url_regex ~r/\/note\/([a-z0-9-]+)/ + @derive { + Flop.Schema, + filterable: [:name, :kind], sortable: [:name], default_limit: 10, max_limit: 100 + } @derive {Jason.Encoder, only: [:id, :name, :content, :slug, :channels, :tags]} schema "notes" do field :content, :string diff --git a/lib/chiya_web/components/layouts/root_public.html.heex b/lib/chiya_web/components/layouts/root_public.html.heex index a5de577..976968b 100644 --- a/lib/chiya_web/components/layouts/root_public.html.heex +++ b/lib/chiya_web/components/layouts/root_public.html.heex @@ -98,7 +98,7 @@ - +
<%= @inner_content %>
diff --git a/lib/chiya_web/components/public_components.ex b/lib/chiya_web/components/public_components.ex index 6d49acd..40e7ef0 100644 --- a/lib/chiya_web/components/public_components.ex +++ b/lib/chiya_web/components/public_components.ex @@ -58,16 +58,13 @@ defmodule ChiyaWeb.PublicComponents do

<%= render_slot(@inner_block) %>

-

+

<%= render_slot(@subtitle) %>

""" end - + attr :note, :map, required: true def featured_images(assigns) do diff --git a/lib/chiya_web/controllers/page_controller.ex b/lib/chiya_web/controllers/page_controller.ex index 958979c..2005e30 100644 --- a/lib/chiya_web/controllers/page_controller.ex +++ b/lib/chiya_web/controllers/page_controller.ex @@ -4,17 +4,24 @@ defmodule ChiyaWeb.PageController do plug :put_layout, html: {ChiyaWeb.Layouts, :public} - def home(conn, _params) do + def home(conn, params) do settings = conn.assigns.settings - channel = + {channel, notes, meta} = case settings.home_channel_id do - nil -> nil - id -> Channels.get_channel!(id) |> Channels.preload_channel_public() + nil -> + nil + + id -> + channel = Channels.get_channel!(id) + {:ok, {notes, meta}} = Chiya.Notes.list_home_notes(channel, params) + {channel, notes, meta} end render(conn, :home, channel: channel, + notes: notes, + meta: meta, page_title: "Home" ) end @@ -81,7 +88,7 @@ defmodule ChiyaWeb.PageController do ) else render_error(conn, :not_found) - end + end end def bookmarks(conn, _params) do @@ -96,6 +103,6 @@ defmodule ChiyaWeb.PageController do ) else render_error(conn, :not_found) - end + end end end diff --git a/lib/chiya_web/controllers/page_html.ex b/lib/chiya_web/controllers/page_html.ex index 0d29996..69fceae 100644 --- a/lib/chiya_web/controllers/page_html.ex +++ b/lib/chiya_web/controllers/page_html.ex @@ -6,7 +6,7 @@ defmodule ChiyaWeb.PageHTML do embed_templates "page_html/*" attr :notes, :list, required: true - attr :layout, :atom, default: :default + attr :layout, :atom, default: :default attr :show_content, :boolean, default: true def note_list(assigns) diff --git a/lib/chiya_web/controllers/page_html/bookmarks.html.heex b/lib/chiya_web/controllers/page_html/bookmarks.html.heex index a3ad633..cefc2c7 100644 --- a/lib/chiya_web/controllers/page_html/bookmarks.html.heex +++ b/lib/chiya_web/controllers/page_html/bookmarks.html.heex @@ -11,4 +11,3 @@ <.tag_bar notes={@notes} /> - diff --git a/lib/chiya_web/controllers/page_html/home.html.heex b/lib/chiya_web/controllers/page_html/home.html.heex index 190a0a9..b62862b 100644 --- a/lib/chiya_web/controllers/page_html/home.html.heex +++ b/lib/chiya_web/controllers/page_html/home.html.heex @@ -1,3 +1,3 @@ -<%= if @channel do %> - <.note_list notes={@channel.notes} layout={@channel.layout} /> -<% end %> +<.note_list notes={@notes} layout={@channel.layout} /> + + diff --git a/lib/chiya_web/controllers/page_html/note.html.heex b/lib/chiya_web/controllers/page_html/note.html.heex index a0a9993..3782e46 100644 --- a/lib/chiya_web/controllers/page_html/note.html.heex +++ b/lib/chiya_web/controllers/page_html/note.html.heex @@ -57,7 +57,6 @@ <% end %> - - diff --git a/lib/chiya_web/controllers/page_html/note_list.html.heex b/lib/chiya_web/controllers/page_html/note_list.html.heex index 0b8b4b8..e94dbe0 100644 --- a/lib/chiya_web/controllers/page_html/note_list.html.heex +++ b/lib/chiya_web/controllers/page_html/note_list.html.heex @@ -1,9 +1,9 @@ <%= if @layout == :default do %> - <.note_list_default notes={@notes} show_content={@show_content}/> + <.note_list_default notes={@notes} show_content={@show_content} /> <% end %> <%= if @layout == :gallery do %> - <.note_list_gallery notes={@notes} show_content={@show_content}/> + <.note_list_gallery notes={@notes} show_content={@show_content} /> <% end %> <%= if @layout == :microblog do %> - <.note_list_microblog notes={@notes} show_content={@show_content}/> + <.note_list_microblog notes={@notes} show_content={@show_content} /> <% end %> diff --git a/lib/chiya_web/controllers/page_html/note_list_default.html.heex b/lib/chiya_web/controllers/page_html/note_list_default.html.heex index ef482dc..9885f4e 100644 --- a/lib/chiya_web/controllers/page_html/note_list_default.html.heex +++ b/lib/chiya_web/controllers/page_html/note_list_default.html.heex @@ -1,10 +1,7 @@
<%= for note <- assigns.notes do %> <% end %> -
\ No newline at end of file + diff --git a/lib/chiya_web/controllers/page_html/tag.html.heex b/lib/chiya_web/controllers/page_html/tag.html.heex index 56583a6..f4b48cd 100644 --- a/lib/chiya_web/controllers/page_html/tag.html.heex +++ b/lib/chiya_web/controllers/page_html/tag.html.heex @@ -11,4 +11,4 @@
<.tag_bar notes={@tag.notes} />
- \ No newline at end of file + diff --git a/lib/chiya_web/controllers/page_html/tag_bar.html.heex b/lib/chiya_web/controllers/page_html/tag_bar.html.heex index da5267a..21bd231 100644 --- a/lib/chiya_web/controllers/page_html/tag_bar.html.heex +++ b/lib/chiya_web/controllers/page_html/tag_bar.html.heex @@ -10,9 +10,12 @@ href={~p"/tagged-with/#{tag.slug}"} class="border border-theme-background1 rounded font-sm px-2 py-1 inline-block mb-2 hover:bg-theme-background1 transition" > - <%= tag.name %> <%= Enum.count(tag.notes) %> + <%= tag.name %> + + <%= Enum.count(tag.notes) %> + <% end %> <% end %> - \ No newline at end of file + diff --git a/lib/chiya_web/controllers/page_html/tag_list.html.heex b/lib/chiya_web/controllers/page_html/tag_list.html.heex index 43f194a..2a4b969 100644 --- a/lib/chiya_web/controllers/page_html/tag_list.html.heex +++ b/lib/chiya_web/controllers/page_html/tag_list.html.heex @@ -3,7 +3,7 @@ <%= if @linked do %> # - + <%= tag.name %> @@ -17,4 +17,4 @@ <% end %> <% end %> - \ No newline at end of file + diff --git a/lib/chiya_web/controllers/page_html/wiki.html.heex b/lib/chiya_web/controllers/page_html/wiki.html.heex index d1f29dd..e787c2e 100644 --- a/lib/chiya_web/controllers/page_html/wiki.html.heex +++ b/lib/chiya_web/controllers/page_html/wiki.html.heex @@ -11,4 +11,4 @@ - \ No newline at end of file + diff --git a/lib/chiya_web/plugs/plug_micropub/handler_behaviour.ex b/lib/chiya_web/plugs/plug_micropub/handler_behaviour.ex index 63e09b3..d610d89 100644 --- a/lib/chiya_web/plugs/plug_micropub/handler_behaviour.ex +++ b/lib/chiya_web/plugs/plug_micropub/handler_behaviour.ex @@ -58,4 +58,4 @@ defmodule ChiyaWeb.Plugs.PlugMicropub.HandlerBehaviour do @callback handle_media(file :: Plug.Upload.t(), access_token) :: {:ok, url :: String.t()} | handler_error -end \ No newline at end of file +end diff --git a/mix.exs b/mix.exs index 63bb814..40cbb4b 100644 --- a/mix.exs +++ b/mix.exs @@ -40,6 +40,8 @@ defmodule Chiya.MixProject do {:ecto_sql, "~> 3.6"}, {:finch, "~> 0.16"}, {:floki, ">= 0.30.0", only: :test}, + {:flop, "~> 0.22.1"}, + {:flop_phoenix, "~> 0.21.1"}, {:gettext, "~> 0.23"}, {:jason, "~> 1.2"}, {:oban, "~> 2.14"}, diff --git a/mix.lock b/mix.lock index e10ba23..d40cb35 100644 --- a/mix.lock +++ b/mix.lock @@ -20,6 +20,8 @@ "file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"}, "finch": {:hex, :finch, "0.16.0", "40733f02c89f94a112518071c0a91fe86069560f5dbdb39f9150042f44dcfb1a", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: false]}, {:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.3", [hex: :mint, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.4 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:nimble_pool, "~> 0.2.6 or ~> 1.0", [hex: :nimble_pool, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "f660174c4d519e5fec629016054d60edd822cdfe2b7270836739ac2f97735ec5"}, "floki": {:hex, :floki, "0.34.3", "5e2dcaec5d7c228ce5b1d3501502e308b2d79eb655e4191751a1fe491c37feac", [:mix], [], "hexpm", "9577440eea5b97924b4bf3c7ea55f7b8b6dce589f9b28b096cc294a8dc342341"}, + "flop": {:hex, :flop, "0.22.1", "4eb5dc1c159845e31d33cd8e73e249b84d013d3b9b1fb17619e70d55fbd2b025", [:mix], [{:ecto, "~> 3.10.3", [hex: :ecto, repo: "hexpm", optional: false]}, {:nimble_options, "~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}], "hexpm", "2f212238d92a8fcc2adadf20dcd875c6f8b4e1ce38ca6bc3f805918a5be567e4"}, + "flop_phoenix": {:hex, :flop_phoenix, "0.21.1", "7b7c143e751f985a94624461a25916d1c604a8a3913253f9a38ae619577853d7", [:mix], [{:flop, "~> 0.22.0", [hex: :flop, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.6.0 or ~> 1.7.0", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 3.3.0", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:phoenix_live_view, "~> 0.19.0", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}], "hexpm", "c44ccdda6d8b8dba4b7c885b7173150dc7388e1f5d63bd834d136fbd538f7b4b"}, "gettext": {:hex, :gettext, "0.23.1", "821e619a240e6000db2fc16a574ef68b3bd7fe0167ccc264a81563cc93e67a31", [:mix], [{:expo, "~> 0.4.0", [hex: :expo, repo: "hexpm", optional: false]}], "hexpm", "19d744a36b809d810d610b57c27b934425859d158ebd56561bc41f7eeb8795db"}, "hackney": {:hex, :hackney, "1.18.2", "d7ff544ddae5e1cb49e9cf7fa4e356d7f41b283989a1c304bfc47a8cc1cf966f", [:rebar3], [{:certifi, "~> 2.12.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~> 6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~> 1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~> 1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.4.1", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~> 1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "af94d5c9f97857db257090a4a10e5426ecb6f4918aa5cc666798566ae14b65fd"}, "hpax": {:hex, :hpax, "0.1.2", "09a75600d9d8bbd064cdd741f21fc06fc1f4cf3d0fcc335e5aa19be1a7235c84", [:mix], [], "hexpm", "2c87843d5a23f5f16748ebe77969880e29809580efdaccd615cd3bed628a8c13"}, @@ -48,6 +50,8 @@ "poison": {:hex, :poison, "4.0.1", "bcb755a16fac91cad79bfe9fc3585bb07b9331e50cfe3420a24bcc2d735709ae", [:mix], [], "hexpm", "ba8836feea4b394bb718a161fc59a288fe0109b5006d6bdf97b6badfcf6f0f25"}, "postgrex": {:hex, :postgrex, "0.17.3", "c92cda8de2033a7585dae8c61b1d420a1a1322421df84da9a82a6764580c503d", [:mix], [{:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "946cf46935a4fdca7a81448be76ba3503cff082df42c6ec1ff16a4bdfbfb098d"}, "ranch": {:hex, :ranch, "1.8.0", "8c7a100a139fd57f17327b6413e4167ac559fbc04ca7448e9be9057311597a1d", [:make, :rebar3], [], "hexpm", "49fbcfd3682fab1f5d109351b61257676da1a2fdbe295904176d5e521a2ddfe5"}, + "scrivener": {:hex, :scrivener, "2.7.2", "1d913c965ec352650a7f864ad7fd8d80462f76a32f33d57d1e48bc5e9d40aba2", [:mix], [], "hexpm", "7866a0ec4d40274efbee1db8bead13a995ea4926ecd8203345af8f90d2b620d9"}, + "scrivener_html": {:git, "https://github.com/workshops-de/scrivener_html", "80752fe8fcb7cd616adf6b5e78c226f158013ddf", []}, "slugger": {:hex, :slugger, "0.3.0", "efc667ab99eee19a48913ccf3d038b1fb9f165fa4fbf093be898b8099e61b6ed", [:mix], [], "hexpm", "20d0ded0e712605d1eae6c5b4889581c3460d92623a930ddda91e0e609b5afba"}, "slugify": {:hex, :slugify, "1.3.1", "0d3b8b7e5c1eeaa960e44dce94382bee34a39b3ea239293e457a9c5b47cc6fd3", [:mix], [], "hexpm", "cb090bbeb056b312da3125e681d98933a360a70d327820e4b7f91645c4d8be76"}, "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.7", "354c321cf377240c7b8716899e182ce4890c5938111a1296add3ec74cf1715df", [:make, :mix, :rebar3], [], "hexpm", "fe4c190e8f37401d30167c8c405eda19469f34577987c76dde613e838bbc67f8"}, diff --git a/test/chiya_web/indie/micropub_test.exs b/test/chiya_web/indie/micropub_test.exs index 1d61c6b..a6825c9 100644 --- a/test/chiya_web/indie/micropub_test.exs +++ b/test/chiya_web/indie/micropub_test.exs @@ -48,7 +48,7 @@ defmodule ChiyaWeb.MicropubTest do assert {:ok, %Note{} = note} = Micropub.update_note(note, %{"category" => ["foo", "bar"]}, %{}, %{}) - IO.inspect(note) + IO.inspect(note) assert Enum.empty?(note.tags) == false end