From aaa525267e77748a9ee23c23b45a9215393a2fba Mon Sep 17 00:00:00 2001 From: Inhji Date: Sun, 9 Jul 2023 19:56:47 +0200 Subject: [PATCH 1/6] add defaults for channel --- lib/chiya/channels/channel.ex | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/chiya/channels/channel.ex b/lib/chiya/channels/channel.ex index b2f4d9d..6d4f438 100644 --- a/lib/chiya/channels/channel.ex +++ b/lib/chiya/channels/channel.ex @@ -14,14 +14,16 @@ defmodule Chiya.Channels.Channel do :public, :private, :unlisted - ] + ], + default: :private field :layout, Ecto.Enum, values: [ :default, :microblog, :gallery - ] + ], + default: :default many_to_many :notes, Chiya.Notes.Note, join_through: "channels_notes", From a1930863bf09349bb10390ec1afa223b32af27f0 Mon Sep 17 00:00:00 2001 From: Inhji Date: Sun, 9 Jul 2023 19:56:59 +0200 Subject: [PATCH 2/6] add simple test case --- test/support/simple_case.ex | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 test/support/simple_case.ex diff --git a/test/support/simple_case.ex b/test/support/simple_case.ex new file mode 100644 index 0000000..ec301db --- /dev/null +++ b/test/support/simple_case.ex @@ -0,0 +1,12 @@ +defmodule Chiya.SimpleCase do + use ExUnit.CaseTemplate + + using do + quote do + # The default endpoint for testing + @endpoint ChiyaWeb.Endpoint + + use ChiyaWeb, :verified_routes + end + end +end From e8b4db9340624f26d7d2b42f62341499ac6c1f19 Mon Sep 17 00:00:00 2001 From: Inhji Date: Sun, 9 Jul 2023 19:58:31 +0200 Subject: [PATCH 3/6] show 5 notes per wiki listing --- lib/chiya/notes.ex | 6 ++++-- lib/chiya_web/controllers/page_controller.ex | 11 ++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/chiya/notes.ex b/lib/chiya/notes.ex index 8d220a6..d0f8457 100644 --- a/lib/chiya/notes.ex +++ b/lib/chiya/notes.ex @@ -46,18 +46,20 @@ defmodule Chiya.Notes do |> Repo.preload(@preloads) end - def list_notes_by_channel_published(%Chiya.Channels.Channel{} = channel) do + def list_notes_by_channel_published(%Chiya.Channels.Channel{} = channel, count \\ 10) do list_notes_by_channel_query(channel) |> order_by([n], desc: n.published_at) |> where([n], not is_nil(n.published_at)) + |> limit(^count) |> Repo.all() |> Repo.preload(@preloads) end - def list_notes_by_channel_updated(%Chiya.Channels.Channel{} = channel) do + def list_notes_by_channel_updated(%Chiya.Channels.Channel{} = channel, count \\ 10) do list_notes_by_channel_query(channel) |> order_by([n], desc: n.published_at) |> where([n], not is_nil(n.published_at)) + |> limit(^count) |> Repo.all() |> Repo.preload(@preloads) end diff --git a/lib/chiya_web/controllers/page_controller.ex b/lib/chiya_web/controllers/page_controller.ex index 35944ca..d8c09a6 100644 --- a/lib/chiya_web/controllers/page_controller.ex +++ b/lib/chiya_web/controllers/page_controller.ex @@ -69,12 +69,13 @@ defmodule ChiyaWeb.PageController do [channel, notes_updated, notes_published] = case settings.wiki_channel_id do - nil -> - [nil, nil] - id -> + nil -> + [nil, nil, nil] + + id -> channel = Chiya.Channels.get_channel!(id) - updated = Chiya.Notes.list_notes_by_channel_updated(channel) - published = Chiya.Notes.list_notes_by_channel_published(channel) + updated = Chiya.Notes.list_notes_by_channel_updated(channel, 5) + published = Chiya.Notes.list_notes_by_channel_published(channel, 5) [channel, updated, published] end From 419a58a48e1ae961de236274180d8b495abba9ff Mon Sep 17 00:00:00 2001 From: Inhji Date: Sun, 9 Jul 2023 19:59:47 +0200 Subject: [PATCH 4/6] initial outline code --- lib/chiya_web/outline.ex | 21 +++++++++++++++++++++ test/chiya_web/outline_test.exs | 20 ++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 lib/chiya_web/outline.ex create mode 100644 test/chiya_web/outline_test.exs diff --git a/lib/chiya_web/outline.ex b/lib/chiya_web/outline.ex new file mode 100644 index 0000000..0d88e14 --- /dev/null +++ b/lib/chiya_web/outline.ex @@ -0,0 +1,21 @@ +defmodule ChiyaWeb.Outline do + @outline_regex ~r/\#{1,6}\s.+/ + @heading_regex ~r/^(#+)\s(.+)$/ + + def get(markdown) do + headings = + @outline_regex + |> Regex.scan(markdown, capture: :all) + + Enum.chunk_by(headings, fn h -> nil end) + end + + def level(heading) do + Regex.scan(@heading_regex, heading) + |> Enum.map(fn [_, level, heading] -> + [level_from_string(level), heading] + end) + end + + defp level_from_string(string), do: String.length(string) +end diff --git a/test/chiya_web/outline_test.exs b/test/chiya_web/outline_test.exs new file mode 100644 index 0000000..8722b0b --- /dev/null +++ b/test/chiya_web/outline_test.exs @@ -0,0 +1,20 @@ +defmodule ChiyaWeb.OutlineTest do + use Chiya.SimpleCase + + alias ChiyaWeb.Outline + + describe "extract_outline/1" do + test "extracts headlines from markdown" do + markdown = "# Heading\nsome paragraph\n## Sub Heading\n# Second Heading" + + assert [{1, "Heading", [{2, "Sub Heading", []}]}, {1, "Second Heading", []}] = + Outline.get(markdown) + end + end + + describe "outline_level/1" do + test "extracts outline level" do + assert {1, "Heading"} = Outline.level("# Heading") + end + end +end From ac1db473f994676450cd9a4445a33fb721449516 Mon Sep 17 00:00:00 2001 From: Inhji Date: Sun, 9 Jul 2023 20:00:01 +0200 Subject: [PATCH 5/6] mix format --- .../components/layouts/error.html.heex | 2 +- .../controllers/error_html/404.html.heex | 26 +++++++++---------- .../controllers/error_html/500.html.heex | 26 +++++++++---------- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/lib/chiya_web/components/layouts/error.html.heex b/lib/chiya_web/components/layouts/error.html.heex index f3985a1..0543398 100644 --- a/lib/chiya_web/components/layouts/error.html.heex +++ b/lib/chiya_web/components/layouts/error.html.heex @@ -1 +1 @@ -<%= @inner_content %> \ No newline at end of file +<%= @inner_content %> diff --git a/lib/chiya_web/controllers/error_html/404.html.heex b/lib/chiya_web/controllers/error_html/404.html.heex index 5bc960c..c87ce2e 100644 --- a/lib/chiya_web/controllers/error_html/404.html.heex +++ b/lib/chiya_web/controllers/error_html/404.html.heex @@ -1,14 +1,14 @@ - - Not found - - - - - - <.header class="mx-auto max-w-2xl"> - Not found - <:subtitle>This page went away and never came back. - - - \ No newline at end of file + + Not found + + + + + + <.header class="mx-auto max-w-2xl"> + Not found + <:subtitle>This page went away and never came back. + + + diff --git a/lib/chiya_web/controllers/error_html/500.html.heex b/lib/chiya_web/controllers/error_html/500.html.heex index 66d3b65..084d0bd 100644 --- a/lib/chiya_web/controllers/error_html/500.html.heex +++ b/lib/chiya_web/controllers/error_html/500.html.heex @@ -1,14 +1,14 @@ - - Infernal Server Error - - - - - - <.header class="mx-auto max-w-2xl"> - Infernal Server Error - <:subtitle>Server got hot and went to hell. - - - \ No newline at end of file + + Infernal Server Error + + + + + + <.header class="mx-auto max-w-2xl"> + Infernal Server Error + <:subtitle>Server got hot and went to hell. + + + From ac410636a6279edea0b521b9d18f944566ce28ea Mon Sep 17 00:00:00 2001 From: Inhji Date: Sun, 9 Jul 2023 20:01:03 +0200 Subject: [PATCH 6/6] improve public pages --- .../components/layouts/root_public.html.heex | 17 +++--- lib/chiya_web/components/public_components.ex | 26 +++++++--- .../controllers/page_html/about.html.heex | 25 ++++----- .../controllers/page_html/channel.html.heex | 4 +- .../controllers/page_html/home.html.heex | 4 +- .../controllers/page_html/note.html.heex | 3 +- .../controllers/page_html/tag.html.heex | 4 +- .../controllers/page_html/wiki.html.heex | 52 +++++++++++-------- .../chiya_web/controllers/error_html_test.exs | 4 +- 9 files changed, 77 insertions(+), 62 deletions(-) diff --git a/lib/chiya_web/components/layouts/root_public.html.heex b/lib/chiya_web/components/layouts/root_public.html.heex index be4172c..89da245 100644 --- a/lib/chiya_web/components/layouts/root_public.html.heex +++ b/lib/chiya_web/components/layouts/root_public.html.heex @@ -36,7 +36,7 @@