From 58550fe4f39a3a422aa84f62d5dda103c46f209a Mon Sep 17 00:00:00 2001 From: Inhji Date: Fri, 31 Mar 2023 22:20:32 +0200 Subject: [PATCH 1/3] add note export as raw text --- lib/chiya_web/controllers/note_controller.ex | 11 +++++++++++ lib/chiya_web/exim.ex | 12 ++++++++++++ lib/chiya_web/live/note_show_live.ex | 5 ++++- lib/chiya_web/router.ex | 1 + mix.exs | 3 ++- mix.lock | 3 +++ 6 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 lib/chiya_web/exim.ex diff --git a/lib/chiya_web/controllers/note_controller.ex b/lib/chiya_web/controllers/note_controller.ex index 159823d..8ad0f20 100644 --- a/lib/chiya_web/controllers/note_controller.ex +++ b/lib/chiya_web/controllers/note_controller.ex @@ -64,6 +64,17 @@ defmodule ChiyaWeb.NoteController do |> redirect(to: ~p"/admin/notes") end + def raw(conn, %{"id" => id}) do + raw_note = + id + |> Notes.get_note!() + |> Notes.preload_note() + |> ChiyaWeb.Exim.export_note() + + conn + |> text(raw_note) + end + defp from_channel_ids(note_params) do selected_ids = Enum.map(note_params["channels"] || [], &String.to_integer/1) diff --git a/lib/chiya_web/exim.ex b/lib/chiya_web/exim.ex new file mode 100644 index 0000000..010a328 --- /dev/null +++ b/lib/chiya_web/exim.ex @@ -0,0 +1,12 @@ +defmodule ChiyaWeb.Exim do + alias Chiya.Notes.Note + + defp frontmatter(%Note{name: title, channels: channels}) do + channels_raw = Enum.map_join(channels, "], [", fn c -> "\"#{c.name}\"" end) + "title: \"#{title}\"\ncategories: [#{channels_raw}]" + end + + def export_note(%Note{content: content} = note) do + "---\n#{frontmatter(note)}\n---\n#{content}" + end +end \ No newline at end of file diff --git a/lib/chiya_web/live/note_show_live.ex b/lib/chiya_web/live/note_show_live.ex index 3189156..3c4c104 100644 --- a/lib/chiya_web/live/note_show_live.ex +++ b/lib/chiya_web/live/note_show_live.ex @@ -17,7 +17,10 @@ defmodule ChiyaWeb.NoteShowLive do <.button>Edit note <.link href={~p"/n/#{@note.slug}"}> - <.button>Preview note + <.button>Preview + + <.link href={~p"/admin/notes/#{@note}/raw"}> + <.button>Raw diff --git a/lib/chiya_web/router.ex b/lib/chiya_web/router.ex index af9a0de..b0ebd06 100644 --- a/lib/chiya_web/router.ex +++ b/lib/chiya_web/router.ex @@ -62,6 +62,7 @@ defmodule ChiyaWeb.Router do resources "/identities", IdentityController live "/notes/:id", NoteShowLive, :show + get "/notes/:id/raw", NoteController, :raw end ## Authentication routes diff --git a/mix.exs b/mix.exs index c2f30d2..d85e629 100644 --- a/mix.exs +++ b/mix.exs @@ -53,7 +53,8 @@ defmodule Chiya.MixProject do {:oban, "~> 2.14"}, {:waffle, "~> 1.1"}, {:waffle_ecto, "~> 0.0.12"}, - {:earmark, "~> 1.4"} + {:earmark, "~> 1.4"}, + {:yaml_front_matter, "~> 1.0.0"} ] end diff --git a/mix.lock b/mix.lock index 1da6ccd..5c4ed10 100644 --- a/mix.lock +++ b/mix.lock @@ -56,4 +56,7 @@ "waffle_ecto": {:hex, :waffle_ecto, "0.0.12", "e5c17c49b071b903df71861c642093281123142dc4e9908c930db3e06795b040", [:mix], [{:ecto, "~> 3.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:waffle, "~> 1.0", [hex: :waffle, repo: "hexpm", optional: false]}], "hexpm", "585fe6371057066d2e8e3383ddd7a2437ff0668caf3f4cbf5a041e0de9837168"}, "websock": {:hex, :websock, "0.4.3", "184ac396bdcd3dfceb5b74c17d221af659dd559a95b1b92041ecb51c9b728093", [:mix], [], "hexpm", "5e4dd85f305f43fd3d3e25d70bec4a45228dfed60f0f3b072d8eddff335539cf"}, "websock_adapter": {:hex, :websock_adapter, "0.4.5", "30038a3715067f51a9580562c05a3a8d501126030336ffc6edb53bf57d6d2d26", [:mix], [{:bandit, "~> 0.6", [hex: :bandit, repo: "hexpm", optional: true]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.6", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:websock, "~> 0.4", [hex: :websock, repo: "hexpm", optional: false]}], "hexpm", "1d9812dc7e703c205049426fd4fe0852a247a825f91b099e53dc96f68bafe4c8"}, + "yamerl": {:hex, :yamerl, "0.10.0", "4ff81fee2f1f6a46f1700c0d880b24d193ddb74bd14ef42cb0bcf46e81ef2f8e", [:rebar3], [], "hexpm", "346adb2963f1051dc837a2364e4acf6eb7d80097c0f53cbdc3046ec8ec4b4e6e"}, + "yaml_elixir": {:hex, :yaml_elixir, "2.9.0", "9a256da867b37b8d2c1ffd5d9de373a4fda77a32a45b452f1708508ba7bbcb53", [:mix], [{:yamerl, "~> 0.10", [hex: :yamerl, repo: "hexpm", optional: false]}], "hexpm", "0cb0e7d4c56f5e99a6253ed1a670ed0e39c13fc45a6da054033928607ac08dfc"}, + "yaml_front_matter": {:hex, :yaml_front_matter, "1.0.0", "9f3310906a9647d04fc4715b6bac5ed177defc9625c53b93430d36d8fd0961db", [:mix], [{:yaml_elixir, "~> 2.0", [hex: :yaml_elixir, repo: "hexpm", optional: false]}], "hexpm", "73cf825c18b7a14bfd8fb5856fa4887196035be69d2d45d1c370917aae0572ec"}, } From c9bf01d80fc7ed99923c436be2bee75c5cfa7e7e Mon Sep 17 00:00:00 2001 From: Inhji Date: Fri, 31 Mar 2023 22:20:38 +0200 Subject: [PATCH 2/3] remove icon fill --- assets/css/app.css | 1 - 1 file changed, 1 deletion(-) diff --git a/assets/css/app.css b/assets/css/app.css index 95f241d..caf81fd 100644 --- a/assets/css/app.css +++ b/assets/css/app.css @@ -67,5 +67,4 @@ a[rel] svg { /* Set width and color for identity icons */ svg { width: 1.5em; - @apply fill-emerald-500 dark:fill-emerald-700; } \ No newline at end of file From f9af1e709c8b4f22b0f5562ef209d75fdfd7cd8d Mon Sep 17 00:00:00 2001 From: Inhji Date: Fri, 31 Mar 2023 22:56:34 +0200 Subject: [PATCH 3/3] add gruvbox theme --- assets/css/app.css | 18 ++++++++++++++++++ lib/chiya/site/setting.ex | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/assets/css/app.css b/assets/css/app.css index caf81fd..128449d 100644 --- a/assets/css/app.css +++ b/assets/css/app.css @@ -41,6 +41,24 @@ --color-text-muted: 76 87 111; --color-text-dim: 57 65 83; } + + :root[data-theme=gruvbox] { + --color-primary: 175 58 3; + --color-background: 251 241 199; + --color-text-base :40 40 40; + --color-text-heading: 66 123 88; + --color-text-muted: 60 56 54; + --color-text-dim: 102 92 84; + } + + :root[data-theme=gruvbox][data-mode=dark] { + --color-primary: 214 93 14; + --color-background: 40 40 40; + --color-text-base: 251 241 199; + --color-text-heading: 104 157 106; + --color-text-muted: 235 219 178; + --color-text-dim: 189 174 147; + } } /* diff --git a/lib/chiya/site/setting.ex b/lib/chiya/site/setting.ex index d6b5bd3..f90a108 100644 --- a/lib/chiya/site/setting.ex +++ b/lib/chiya/site/setting.ex @@ -9,7 +9,7 @@ defmodule Chiya.Site.Setting do field :custom_css, :string, default: "" field :custom_html, :string, default: "" - field :theme, Ecto.Enum, values: [:default, :frame], default: :default + field :theme, Ecto.Enum, values: [:default, :frame, :gruvbox], default: :default field :user_agent, :string, default: "Chiya/0.x +https://inhji.de"