From c595b206681be439cc608dca9af52f6c4717fc51 Mon Sep 17 00:00:00 2001 From: Inhji Date: Sat, 9 Sep 2023 10:24:22 +0200 Subject: [PATCH] yay --- assets/css/app.css | 109 ++++++++++-------- assets/css/gruvbox.css | 7 -- assets/css/reset.css | 52 --------- assets/tailwind.config.js | 7 +- lib/chiya/tags.ex | 2 +- .../components/layouts/root_public.html.heex | 48 +++----- lib/chiya_web/components/public_components.ex | 2 +- lib/chiya_web/controllers/page_controller.ex | 97 ++++++---------- lib/chiya_web/controllers/page_html.ex | 18 ++- .../controllers/page_html/about.html.heex | 36 +++--- .../controllers/page_html/bookmarks.html.heex | 50 ++------ .../controllers/page_html/channel.html.heex | 24 ++-- .../controllers/page_html/home.html.heex | 2 +- .../controllers/page_html/note.html.heex | 45 ++++---- .../controllers/page_html/note_list.html.heex | 12 +- .../page_html/note_list_default.html.heex | 50 ++++---- .../page_html/note_list_gallery.html.heex | 1 - .../controllers/page_html/tag.html.heex | 30 +++-- .../controllers/page_html/tag_list.html.heex | 18 +++ .../controllers/page_html/wiki.html.heex | 57 ++------- 20 files changed, 272 insertions(+), 395 deletions(-) delete mode 100644 assets/css/gruvbox.css delete mode 100644 assets/css/reset.css create mode 100644 lib/chiya_web/controllers/page_html/tag_list.html.heex diff --git a/assets/css/app.css b/assets/css/app.css index a7fb02f..ac05e90 100644 --- a/assets/css/app.css +++ b/assets/css/app.css @@ -9,70 +9,79 @@ The base layer is for things like reset rules or default styles applied to plain HTML elements. */ @layer base { - :root { - --color-background: 255 255 255; - --color-foreground: 0 0 0; - --color-primary: 0 0 0; - } - - :root[mode=dark] { - --color-background: 0 0 0; - --color-foreground: 255 255 255; - --color-primary: 255 255 255; - } - html { font-family: 'Inter', sans-serif; font-feature-settings: "case", "cpsp", "frac", "salt", "ccmp", "cv01", "cv02", "cv03", "cv04", "cv05", "cv06", "cv07", "cv09", "cv10", "cv11"; + @apply text-slate-800; } - header h1 { @apply text-xl; } - .stack > * + * { margin-block-start: var(--flow-space, 1em); } + + /* + * ============= SITE LAYOUT ============= + */ + + #site-header { + @apply block px-3 py-6 bg-gradient-to-r from-slate-900 to-slate-950 text-white print:hidden; + + nav ul { + @apply flex gap-3; + + a { @apply p-3 rounded hover:bg-primary-500 transition; } + } + } + + #primary-sidebar { + @apply col-span-1; + + nav { + @apply flex flex-col md:flex-row lg:flex-col mb-6 lg:mb-0; + } + + .menu { + @apply flex-1; + + h2 { + @apply font-bold; + } + } + } + + #site-content { + @apply grid grid-cols-1 lg:grid-cols-5 gap-0 lg:gap-12; + + #secondary-sidebar { + @apply col-span-1; + } + + #content-wrapper { + @apply col-span-4; + } + } + + /* + * ============= PAGE LAYOUT ============= + */ + + header.page-header { + @apply border-b border-slate-300; + + > h1 { + @apply text-3xl leading-loose font-bold text-slate-900; + } + + > p { + @apply mb-3; + } + } } /* The components layer is for class-based styles that you want to be able to override with utilities. */ @layer components { - - #site-header { - @apply py-8 block px-3 bg-black text-white print:hidden; - } - - #site-header nav ul { - @apply flex gap-3; - } - - #site-content { - @apply grid grid-cols-1 lg:grid-cols-5 gap-12; - } - - aside#primary-sidebar { - @apply col-span-1; - } - - aside#primary-sidebar nav { - @apply flex flex-col md:flex-row lg:flex-col; - } - aside#primary-sidebar .menu { - @apply flex-1; - } - - aside#primary-sidebar .menu h2 { - @apply font-bold; - } - - aside#secondary-sidebar { - @apply col-span-1; - } - - section#content-wrapper { - @apply col-span-4; - } - .divider { @apply flex items-center my-8 before:flex-1 after:flex-1 before:content-[''] after:content-[''] before:p-[0.5px] after:p-[0.5px] w-full mx-auto last:hidden; } diff --git a/assets/css/gruvbox.css b/assets/css/gruvbox.css deleted file mode 100644 index d82083e..0000000 --- a/assets/css/gruvbox.css +++ /dev/null @@ -1,7 +0,0 @@ -/*! - Theme: Gruvbox dark, hard - Author: Dawid Kurek (dawikur@gmail.com), morhetz (https://github.com/morhetz/gruvbox) - License: ~ MIT (or more permissive) [via base16-schemes-source] - Maintainer: @highlightjs/core-team - Version: 2021.09.0 -*/pre code.hljs{display:block;overflow-x:auto;padding:1em}code.hljs{padding:3px 5px}.hljs{color:#d5c4a1;background:#1d2021}.hljs ::selection,.hljs::selection{background-color:#504945;color:#d5c4a1}.hljs-comment{color:#665c54}.hljs-tag{color:#bdae93}.hljs-operator,.hljs-punctuation,.hljs-subst{color:#d5c4a1}.hljs-operator{opacity:.7}.hljs-bullet,.hljs-deletion,.hljs-name,.hljs-selector-tag,.hljs-template-variable,.hljs-variable{color:#fb4934}.hljs-attr,.hljs-link,.hljs-literal,.hljs-number,.hljs-symbol,.hljs-variable.constant_{color:#fe8019}.hljs-class .hljs-title,.hljs-title,.hljs-title.class_{color:#fabd2f}.hljs-strong{font-weight:700;color:#fabd2f}.hljs-addition,.hljs-code,.hljs-string,.hljs-title.class_.inherited__{color:#b8bb26}.hljs-built_in,.hljs-doctag,.hljs-keyword.hljs-atrule,.hljs-quote,.hljs-regexp{color:#8ec07c}.hljs-attribute,.hljs-function .hljs-title,.hljs-section,.hljs-title.function_,.ruby .hljs-property{color:#83a598}.diff .hljs-meta,.hljs-keyword,.hljs-template-tag,.hljs-type{color:#d3869b}.hljs-emphasis{color:#d3869b;font-style:italic}.hljs-meta,.hljs-meta .hljs-keyword,.hljs-meta .hljs-string{color:#d65d0e}.hljs-meta .hljs-keyword,.hljs-meta-keyword{font-weight:700} \ No newline at end of file diff --git a/assets/css/reset.css b/assets/css/reset.css deleted file mode 100644 index b37fa30..0000000 --- a/assets/css/reset.css +++ /dev/null @@ -1,52 +0,0 @@ -/* - 1. Use a more-intuitive box-sizing model. -*/ -*, *::before, *::after { - box-sizing: border-box; -} -/* - 2. Remove default margin -*/ -* { - margin: 0; -} -/* - 3. Allow percentage-based heights in the application -*/ -html, body { - height: 100%; -} -/* - Typographic tweaks! - 4. Add accessible line-height - 5. Improve text rendering -*/ -body { - line-height: 1.5; - -webkit-font-smoothing: antialiased; -} -/* - 6. Improve media defaults -*/ -img, picture, video, canvas, svg { - display: block; - max-width: 100%; -} -/* - 7. Remove built-in form typography styles -*/ -input, button, textarea, select { - font: inherit; -} -/* - 8. Avoid text overflows -*/ -p, h1, h2, h3, h4, h5, h6 { - overflow-wrap: break-word; -} -/* - 9. Create a root stacking context -*/ -#root, #__next { - isolation: isolate; -} \ No newline at end of file diff --git a/assets/tailwind.config.js b/assets/tailwind.config.js index bd0de9d..496bda4 100644 --- a/assets/tailwind.config.js +++ b/assets/tailwind.config.js @@ -14,7 +14,12 @@ module.exports = { ], darkMode: ['class', '[data-mode="dark"]'], theme: { - container: { center: true } + container: { center: true }, + extend: { + colors: { + primary: colors.pink + } + } }, plugins: [ require("@tailwindcss/forms"), diff --git a/lib/chiya/tags.ex b/lib/chiya/tags.ex index 566b363..2d2d382 100644 --- a/lib/chiya/tags.ex +++ b/lib/chiya/tags.ex @@ -8,7 +8,7 @@ defmodule Chiya.Tags do alias Chiya.Tags.Tag - @preloads [notes: [:tags]] + @preloads [notes: [tags: [:notes]]] defp with_preloads(query), do: preload(query, ^@preloads) @doc """ diff --git a/lib/chiya_web/components/layouts/root_public.html.heex b/lib/chiya_web/components/layouts/root_public.html.heex index f1cc13b..183627f 100644 --- a/lib/chiya_web/components/layouts/root_public.html.heex +++ b/lib/chiya_web/components/layouts/root_public.html.heex @@ -74,20 +74,26 @@ @@ -139,13 +131,5 @@ <%= @profile.bio %> <% end %> - -
-
-
-
-
-
-
diff --git a/lib/chiya_web/components/public_components.ex b/lib/chiya_web/components/public_components.ex index 845e911..4959de0 100644 --- a/lib/chiya_web/components/public_components.ex +++ b/lib/chiya_web/components/public_components.ex @@ -76,7 +76,7 @@ defmodule ChiyaWeb.PublicComponents do <%= tag.name %> <% end %> - <.dot class="text-theme-base/50 last:hidden" /> + <.dot class="last:hidden" /> <% end %> """ diff --git a/lib/chiya_web/controllers/page_controller.ex b/lib/chiya_web/controllers/page_controller.ex index 42c62af..958979c 100644 --- a/lib/chiya_web/controllers/page_controller.ex +++ b/lib/chiya_web/controllers/page_controller.ex @@ -1,5 +1,6 @@ defmodule ChiyaWeb.PageController do use ChiyaWeb, :controller + alias Chiya.Channels plug :put_layout, html: {ChiyaWeb.Layouts, :public} @@ -9,7 +10,7 @@ defmodule ChiyaWeb.PageController do channel = case settings.home_channel_id do nil -> nil - id -> Chiya.Channels.get_channel!(id) |> Chiya.Channels.preload_channel_public() + id -> Channels.get_channel!(id) |> Channels.preload_channel_public() end render(conn, :home, @@ -20,8 +21,8 @@ defmodule ChiyaWeb.PageController do def channel(conn, %{"slug" => channel_slug}) do channel = - Chiya.Channels.get_channel_by_slug!(channel_slug) - |> Chiya.Channels.preload_channel_public() + Channels.get_channel_by_slug!(channel_slug) + |> Channels.preload_channel_public() render(conn, :channel, channel: channel, @@ -42,14 +43,14 @@ defmodule ChiyaWeb.PageController do note = Chiya.Notes.get_note_by_slug_preloaded!(note_slug) changeset = Chiya.Notes.change_note_comment(%Chiya.Notes.NoteComment{}, %{note_id: note.id}) - if is_nil(note.published_at) and is_nil(conn.assigns.current_user) do - render_error(conn, :not_found) - else + if note.published_at || conn.assigns.current_user do render(conn, :note, note: note, page_title: note.name, changeset: changeset ) + else + render_error(conn, :not_found) end end @@ -57,66 +58,44 @@ defmodule ChiyaWeb.PageController do note = Chiya.Notes.get_note_by_slug_preloaded("about") user = Chiya.Accounts.get_user!(1) - render(conn, :about, - note: note, - user: user, - page_title: "About" - ) + if note && user do + render(conn, :about, + note: note, + user: user, + page_title: "About" + ) + else + render_error(conn, :not_found) + end end def wiki(conn, _params) do - [channel, notes_updated, notes_published] = - case conn.assigns.settings.wiki_channel_id do - nil -> - [nil, nil, nil] + if id = conn.assigns.settings.wiki_channel_id do + channel = Chiya.Channels.get_channel!(id) + notes = Chiya.Notes.list_notes_by_channel_updated(channel, 999) - id -> - channel = Chiya.Channels.get_channel!(id) - updated = Chiya.Notes.list_notes_by_channel_updated(channel, 5) - published = Chiya.Notes.list_notes_by_channel_published(channel, 5) - [channel, updated, published] - end - - render(conn, :wiki, - channel: channel, - notes_updated: notes_updated, - notes_published: notes_published, - page_title: "Wiki" - ) + render(conn, :wiki, + channel: channel, + notes: notes, + page_title: "Wiki" + ) + else + render_error(conn, :not_found) + end end def bookmarks(conn, _params) do - [channel, notes, tags] = - case conn.assigns.settings.bookmark_channel_id do - nil -> - [nil, nil] + if id = conn.assigns.settings.bookmark_channel_id do + channel = Chiya.Channels.get_channel!(id) + notes = Chiya.Notes.list_notes_by_channel_published(channel, 999) - id -> - channel = Chiya.Channels.get_channel!(id) - notes = Chiya.Notes.list_notes_by_channel_published(channel, 999) - tags = group_tags(notes) - - [channel, notes, tags] - end - - render(conn, :bookmarks, - channel: channel, - notes: notes, - tags: tags, - page_title: "Bookmarks" - ) - end - - defp group_tags(notes) do - Enum.reduce(notes, [], fn n, acc -> - acc ++ n.tags - end) - |> Enum.uniq_by(fn t -> t.id end) - |> Enum.sort_by(fn t -> t.slug end, :asc) - |> Enum.group_by( - fn n -> String.first(n.name) end, - fn n -> n end - ) - |> IO.inspect() + render(conn, :bookmarks, + channel: channel, + notes: notes, + page_title: "Bookmarks" + ) + else + render_error(conn, :not_found) + end end end diff --git a/lib/chiya_web/controllers/page_html.ex b/lib/chiya_web/controllers/page_html.ex index 824983d..27cd57f 100644 --- a/lib/chiya_web/controllers/page_html.ex +++ b/lib/chiya_web/controllers/page_html.ex @@ -5,7 +5,11 @@ defmodule ChiyaWeb.PageHTML do embed_templates "page_html/*" - + attr :notes, :list, required: true + attr :layout, :atom, default: :default + attr :show_content, :boolean, default: true + def note_list(assigns) + attr :notes, :list, required: true attr :show_content, :boolean, default: true def note_list_default(assigns) @@ -47,4 +51,16 @@ defmodule ChiyaWeb.PageHTML do ] ) end + + def group_tags(notes) do + Enum.reduce(notes, [], fn n, acc -> + acc ++ n.tags + end) + |> Enum.uniq_by(fn t -> t.id end) + |> Enum.sort_by(fn t -> t.slug end, :asc) + |> Enum.group_by( + fn n -> String.first(n.name) end, + fn n -> n end + ) + end end diff --git a/lib/chiya_web/controllers/page_html/about.html.heex b/lib/chiya_web/controllers/page_html/about.html.heex index f6b694b..37ebc0e 100644 --- a/lib/chiya_web/controllers/page_html/about.html.heex +++ b/lib/chiya_web/controllers/page_html/about.html.heex @@ -1,20 +1,18 @@ -
-
-
- - <.header class="flex-1"> - <%= @user.name %> - <:subtitle><%= @user.bio %> - -
+
+
+ + +
- <%= if @note do %> -
- <%= Markdown.render(@note.content) |> raw %> -
- <% end %> -
-
+ <%= if @note do %> +
+ <%= Markdown.render(@note.content) |> raw %> +
+ <% end %> + diff --git a/lib/chiya_web/controllers/page_html/bookmarks.html.heex b/lib/chiya_web/controllers/page_html/bookmarks.html.heex index e021beb..7fa0764 100644 --- a/lib/chiya_web/controllers/page_html/bookmarks.html.heex +++ b/lib/chiya_web/controllers/page_html/bookmarks.html.heex @@ -1,40 +1,14 @@ -<%= if @channel do %> -
-

<%= Enum.count(@notes) %> Bookmarks

-
+ -
-
- <%= if @channel.layout == :default do %> - <.note_list_default notes={@notes}/> - <% end %> - <%= if @channel.layout == :gallery do %> - <.note_list_gallery notes={@notes}/> - <% end %> - <%= if @channel.layout == :microblog do %> - <.note_list_microblog notes={@notes}/> - <% end %> -
- -
- -
+
+
+ <.note_list notes={@notes} layout={@channel.layout} />
-<% end %> + +
+ <.tag_list notes={@notes} /> +
+
+ diff --git a/lib/chiya_web/controllers/page_html/channel.html.heex b/lib/chiya_web/controllers/page_html/channel.html.heex index a2e7a08..f1b51ae 100644 --- a/lib/chiya_web/controllers/page_html/channel.html.heex +++ b/lib/chiya_web/controllers/page_html/channel.html.heex @@ -1,18 +1,8 @@ -
- <.header> - <%= @channel.name %> - <:subtitle><%= Markdown.render(@channel.content) |> raw %> - + -
- <%= if @channel.layout == :default do %> - <.note_list_default notes={@channel.notes}/> - <% end %> - <%= if @channel.layout == :gallery do %> - <.note_list_gallery notes={@channel.notes}/> - <% end %> - <%= if @channel.layout == :microblog do %> - <.note_list_microblog notes={@channel.notes}/> - <% end %> -
-
+
+ <.note_list notes={@channel.notes}/> +
\ No newline at end of file diff --git a/lib/chiya_web/controllers/page_html/home.html.heex b/lib/chiya_web/controllers/page_html/home.html.heex index 6a1d84c..190a0a9 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} channel={@channel} /> + <.note_list notes={@channel.notes} layout={@channel.layout} /> <% end %> diff --git a/lib/chiya_web/controllers/page_html/note.html.heex b/lib/chiya_web/controllers/page_html/note.html.heex index b1e982a..ccff72d 100644 --- a/lib/chiya_web/controllers/page_html/note.html.heex +++ b/lib/chiya_web/controllers/page_html/note.html.heex @@ -9,10 +9,14 @@
@@ -50,25 +54,24 @@ <% end %>