fix identities on home page and in head, mix format

This commit is contained in:
Inhji 2023-05-25 21:23:04 +02:00
parent db51df78a9
commit df0af6af46
15 changed files with 172 additions and 102 deletions

View file

@ -61,8 +61,7 @@ config :waffle,
storage_dir_prefix: "priv/waffle/public"
# Configure Timezones with :tz
config :elixir,
:time_zone_database, Tz.TimeZoneDatabase
config :elixir, :time_zone_database, Tz.TimeZoneDatabase
# Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.

View file

@ -8,16 +8,20 @@ defmodule Chiya.Channels.Channel do
field :content, :string
field :name, :string
field :slug, ChannelSlug.Type
field :visibility, Ecto.Enum, values: [
:public,
:private,
:unlisted
]
field :layout, Ecto.Enum, values: [
:default,
:microblog,
:gallery
]
field :visibility, Ecto.Enum,
values: [
:public,
:private,
:unlisted
]
field :layout, Ecto.Enum,
values: [
:default,
:microblog,
:gallery
]
many_to_many :notes, Chiya.Notes.Note,
join_through: "channels_notes",

View file

@ -333,7 +333,8 @@ defmodule ChiyaWeb.CoreComponents do
attr :multiple, :boolean, default: false, doc: "the multiple flag for select inputs"
attr :rest, :global,
include: ~w(autocomplete accept cols disabled form max maxlength min minlength pattern placeholder readonly required rows size step)
include:
~w(autocomplete accept cols disabled form max maxlength min minlength pattern placeholder readonly required rows size step)
slot :inner_block

View file

@ -1,42 +1,42 @@
<header class="px-4 sm:px-6 lg:px-8">
<div class="flex items-center justify-end border-b border-gray-300 dark:border-gray-800 py-3">
<% items = [
%{
path: ~p"/admin/notes",
icon: "hero-document-text-solid",
name: "Notes"
},
%{
path: ~p"/admin/comments",
icon: "hero-chat-bubble-oval-left-ellipsis-solid",
name: "Comments"
},
%{
path: ~p"/admin/channels",
icon: "hero-speaker-wave-solid",
name: "Channels"
},
%{
path: ~p"/admin/identities",
icon: "hero-user-solid",
name: "Identities"
},
%{
path: ~p"/admin/settings",
icon: "hero-wrench-screwdriver-solid",
name: "Settings"
}
] %>
%{
path: ~p"/admin/notes",
icon: "hero-document-text-solid",
name: "Notes"
},
%{
path: ~p"/admin/comments",
icon: "hero-chat-bubble-oval-left-ellipsis-solid",
name: "Comments"
},
%{
path: ~p"/admin/channels",
icon: "hero-speaker-wave-solid",
name: "Channels"
},
%{
path: ~p"/admin/identities",
icon: "hero-user-solid",
name: "Identities"
},
%{
path: ~p"/admin/settings",
icon: "hero-wrench-screwdriver-solid",
name: "Settings"
}
] %>
<div class="flex items-center gap-4">
<%= for item <- items do %>
<.link
href={item.path}
class="text-xs font-semibold leading-6 text-gray-900 hover:text-gray-700 dark:text-gray-200"
>
<.icon name={item.icon} class="w-4 h-4" />
<span class="align-sub"><%= item.name %></span>
</.link>
<% end %>
<%= for item <- items do %>
<.link
href={item.path}
class="text-xs font-semibold leading-6 text-gray-900 hover:text-gray-700 dark:text-gray-200"
>
<.icon name={item.icon} class="w-4 h-4" />
<span class="align-sub"><%= item.name %></span>
</.link>
<% end %>
</div>
</div>
</header>

View file

@ -10,8 +10,8 @@
<.favicon />
<link rel="preconnect" href="https://rsms.me/">
<link rel="stylesheet" href="https://rsms.me/inter/inter.css">
<link rel="preconnect" href="https://rsms.me/" />
<link rel="stylesheet" href="https://rsms.me/inter/inter.css" />
<link phx-track-static rel="stylesheet" href={~p"/assets/app.css"} />
<script defer phx-track-static type="text/javascript" src={~p"/assets/app.js"}>
</script>

View file

@ -10,8 +10,12 @@
<.favicon />
<link rel="preconnect" href="https://rsms.me/">
<link rel="stylesheet" href="https://rsms.me/inter/inter.css">
<%= for identity <- @identities do %>
<link rel="me" href={identity.url} />
<% end %>
<link rel="preconnect" href="https://rsms.me/" />
<link rel="stylesheet" href="https://rsms.me/inter/inter.css" />
<link phx-track-static rel="stylesheet" href={~p"/assets/app.css"} />
<script defer phx-track-static type="text/javascript" src={~p"/assets/public.js"}>
</script>
@ -31,7 +35,12 @@
<nav>
<ul class="flex gap-3">
<li>
<a href="/" class="text-theme-base px-3 py-2.5 border border-theme-background1 hover:bg-theme-background1 rounded transition font-semibold"><.icon name="hero-home" /> Home</a>
<a
href="/"
class="text-theme-base px-3 py-2.5 border border-theme-background1 hover:bg-theme-background1 rounded transition font-semibold"
>
<.icon name="hero-home" /> Home
</a>
</li>
</ul>
</nav>
@ -47,17 +56,17 @@
<.dot />
<span>Made by Inhji</span>
<.dot />
<span>Struggling to make a decent website since 2011</span>
<span>Struggling to make a decent website since 2011</span>
</p>
<p>
<%= for identity <- @identities do %>
<span><a href={identity.url}><%= identity.name %></a></span>
<%= for identity <- @public_identities do %>
<span><a href={identity.url}><%= identity.name %></a></span>
<.dot />
<% end %>
<span><a href={~p"/about"}>About</a></span>
<.dot />
<% end %>
<span><a href={~p"/about"}>About</a></span>
<.dot />
<span><a href={~p"/admin"}>Admin</a></span>
<span><a href={~p"/admin"}>Admin</a></span>
</p>
</footer>
</body>

View file

@ -14,20 +14,19 @@ defmodule ChiyaWeb.PublicComponents do
@doc """
Renders a middot as divider
"""
def dot(assigns), do:
~H"""
def dot(assigns),
do: ~H"""
<span class="text-theme-primary font-bold">·</span>
"""
@doc """
Renders a horizontal line
"""
def line(assigns), do:
~H"""
def line(assigns),
do: ~H"""
<hr class="my-6 border-theme-base/20" />
"""
@doc """
Renders a note-header with title.
"""
@ -107,7 +106,7 @@ defmodule ChiyaWeb.PublicComponents do
<%= for note <- assigns.notes do %>
<article class="mt-8 first:mt-0">
<div class="prose prose-gruvbox">
<%= raw render(note.content) %>
<%= raw(render(note.content)) %>
</div>
<footer class="mt-1">
<time class="text-theme-base/75">
@ -125,7 +124,8 @@ defmodule ChiyaWeb.PublicComponents do
</section>
"""
_ -> # default, show headings only
# default, show headings only
_ ->
~H"""
<section class="note-list default | mt-6 sm:w-auto flex flex-col gap-1.5">
<%= for note <- assigns.notes do %>

View file

@ -10,24 +10,28 @@
<section class="mx-auto max-w-xl mt-8 text-sm">
<ul class="flex flex-wrap gap-3">
<li>
<a href="#" class="inline-block text-theme-base px-3 py-2.5 hover:bg-theme-background1 rounded transition font-semibold">
<a
href="#"
class="inline-block text-theme-base px-3 py-2.5 hover:bg-theme-background1 rounded transition font-semibold"
>
<.icon name="hero-megaphone" />
</a>
</li>
<%= for channel <- @channels do %>
<li>
<a href={~p"/c/#{channel.slug}"} class="inline-block text-theme-base px-3 py-2.5 border border-theme-background1 hover:bg-theme-background1 rounded transition font-semibold">
<%= channel.name %>
</a>
</li>
<% end %>
<%= for channel <- @channels do %>
<li>
<a
href={~p"/c/#{channel.slug}"}
class="inline-block text-theme-base px-3 py-2.5 border border-theme-background1 hover:bg-theme-background1 rounded transition font-semibold"
>
<%= channel.name %>
</a>
</li>
<% end %>
</ul>
</section>
<%= if @channel do %>
<section class="mx-auto max-w-xl mt-8 border-t border-theme-background1">
<.note_list notes={@channel.notes} layout={@channel.layout} />
</section>
<section class="mx-auto max-w-xl mt-8 border-t border-theme-background1">
<.note_list notes={@channel.notes} layout={@channel.layout} />
</section>
<% end %>

View file

@ -14,13 +14,13 @@
<span>Last Updated</span>
<time class="font-semibold"><%= pretty_date(@note.updated_at) %></time>
<%= if not Enum.empty?(@note.tags) do %>
<.dot />
<span>Tags</span>
<span>
<%= for tag <- @note.tags do %>
<a href={~p"/t/#{tag.slug}"} class="underline-link font-semibold"><%= tag.name %></a>
<% end %>
</span>
<.dot />
<span>Tags</span>
<span>
<%= for tag <- @note.tags do %>
<a href={~p"/t/#{tag.slug}"} class="underline-link font-semibold"><%= tag.name %></a>
<% end %>
</span>
<% end %>
<%= if @current_user do %>
<.dot />
@ -52,7 +52,7 @@
</a>
<% end %>
</div>
<% end %>
<% end %>
</section>
<section class="mt-8 mx-auto max-w-xl">
@ -80,12 +80,28 @@
<.line />
<.simple_form :let={f} for={@changeset} action={~p"/#{@note.slug}/comment"} class="bg-theme-background -m-3">
<.simple_form
:let={f}
for={@changeset}
action={~p"/#{@note.slug}/comment"}
class="bg-theme-background -m-3"
>
<.error :if={@changeset.action}>
Oops, something went wrong! Please check the errors below.
</.error>
<.input field={f[:author_name]} type="text" placeholder="Name" class="bg-theme-background dark:bg-theme-background border-theme-base/20 dark:border-theme-base/20 text-theme-base dark:text-theme-base placeholder-theme-base/40 dark:placeholder-theme-base/60 dark:focus:border-theme-base/60 dark:focus:border-theme-base/60" />
<.input field={f[:content]} type="textarea" placeholder="Content" rows="3" class="bg-theme-background dark:bg-theme-background border-theme-base/20 dark:border-theme-base/20 text-theme-base dark:text-theme-base placeholder-theme-base/60 dark:placeholder-theme-base/60 focus:border-theme-base/60 dark:focus:border-theme-base/60" />
<.input
field={f[:author_name]}
type="text"
placeholder="Name"
class="bg-theme-background dark:bg-theme-background border-theme-base/20 dark:border-theme-base/20 text-theme-base dark:text-theme-base placeholder-theme-base/40 dark:placeholder-theme-base/60 dark:focus:border-theme-base/60 dark:focus:border-theme-base/60"
/>
<.input
field={f[:content]}
type="textarea"
placeholder="Content"
rows="3"
class="bg-theme-background dark:bg-theme-background border-theme-base/20 dark:border-theme-base/20 text-theme-base dark:text-theme-base placeholder-theme-base/60 dark:placeholder-theme-base/60 focus:border-theme-base/60 dark:focus:border-theme-base/60"
/>
<.input field={f[:note_id]} type="hidden" />
<:actions>
<.button>Submit Comment</.button>

View file

@ -10,8 +10,14 @@ defmodule ChiyaWeb.GlobalAssigns do
identities = Chiya.Identities.list_identities()
conn
|> assign(:identities, identities)
|> assign(:public_identities, Enum.filter(identities, fn i -> i.public && i.active end))
|> assign(
:identities,
Enum.filter(identities, fn i -> i.active end)
)
|> assign(
:public_identities,
Enum.filter(identities, fn i -> i.public && i.active end)
)
end
def fetch_public_channels(conn, _opts) do

View file

@ -0,0 +1,15 @@
defmodule ChiyaWeb.Indie.MicropubHandler do
@impl true
def handle_create(type, properties, access_token) do
properties = handle_uploads(properties)
params = %{type: type, properties: properties}
# Chiya.Notes.create_note
id = 0
{:ok, :created, ""}
end
def handle_create(_, _, _), do: {:error, :insufficient_scope}
defp handle_uploads(props) do
end
end

View file

@ -23,13 +23,13 @@ defmodule ChiyaWeb.NoteShowLive do
<.button>Raw</.button>
</.link>
<%= if is_nil(@note.published_at) do %>
<.link href={~p"/admin/notes/#{@note}/publish"}>
<.button>Publish</.button>
</.link>
<.link href={~p"/admin/notes/#{@note}/publish"}>
<.button>Publish</.button>
</.link>
<% else %>
<.link href={~p"/admin/notes/#{@note}/unpublish"}>
<.button>Un-Publish</.button>
</.link>
<.link href={~p"/amdin/notes/#{@note}/unpublish"}>
<.button>Un-Publish</.button>
</.link>
<% end %>
</:actions>
</.header>
@ -44,7 +44,9 @@ defmodule ChiyaWeb.NoteShowLive do
<:item title="Tags"><%= note_tags(@note.tags) %></:item>
<:item title="Links outgoing"><%= note_links(@note.links_from) %></:item>
<:item title="Links incoming"><%= note_links(@note.links_to) %></:item>
<:item title="Embed"><pre class="p-1 bg-gray-100 text-black rounded select-all">[[<%= @note.slug %>]]</pre></:item>
<:item title="Embed">
<pre class="p-1 bg-gray-100 text-black rounded select-all">[[<%= @note.slug %>]]</pre>
</:item>
</.list>
<.line />

View file

@ -25,6 +25,10 @@ defmodule ChiyaWeb.Router do
plug :accepts, ["json"]
end
pipeline :indie do
plug :accepts, ["json", "html"]
end
# Other scopes may use custom stacks.
scope "/api", ChiyaWeb do
pipe_through :api
@ -113,6 +117,14 @@ defmodule ChiyaWeb.Router do
end
end
## Indie routes
scope "/indie", ChiyaWeb.Indie do
forward "/micropub",
PlugMicropub,
handler: MicropubHandler,
json_encoder: Jason
end
## Public routes
scope "/", ChiyaWeb do

View file

@ -56,7 +56,8 @@ defmodule Chiya.MixProject do
{:waffle_ecto, "~> 0.0.12"},
{:earmark, "~> 1.4"},
{:yaml_front_matter, "~> 1.0.0"},
{:tz, "~> 0.26.1"}
{:tz, "~> 0.26.1"},
{:plug_micropub, git: "https://git.inhji.de/inhji/plug_micropub"}
]
end

View file

@ -44,6 +44,7 @@
"plug": {:hex, :plug, "1.14.0", "ba4f558468f69cbd9f6b356d25443d0b796fbdc887e03fa89001384a9cac638f", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "bf020432c7d4feb7b3af16a0c2701455cbbbb95e5b6866132cb09eb0c29adc14"},
"plug_cowboy": {:hex, :plug_cowboy, "2.6.0", "d1cf12ff96a1ca4f52207c5271a6c351a4733f413803488d75b70ccf44aebec2", [:mix], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:cowboy_telemetry, "~> 0.3", [hex: :cowboy_telemetry, repo: "hexpm", optional: false]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "073cf20b753ce6682ed72905cd62a2d4bd9bad1bf9f7feb02a1b8e525bd94fa6"},
"plug_crypto": {:hex, :plug_crypto, "1.2.3", "8f77d13aeb32bfd9e654cb68f0af517b371fb34c56c9f2b58fe3df1235c1251a", [:mix], [], "hexpm", "b5672099c6ad5c202c45f5a403f21a3411247f164e4a8fab056e5cd8a290f4a2"},
"plug_micropub": {:git, "https://git.inhji.de/inhji/plug_micropub", "c6976ac9510035a78a6b1d1fa2e469cb94aa3248", []},
"postgrex": {:hex, :postgrex, "0.16.5", "fcc4035cc90e23933c5d69a9cd686e329469446ef7abba2cf70f08e2c4b69810", [:mix], [{:connection, "~> 1.1", [hex: :connection, repo: "hexpm", optional: false]}, {: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", "edead639dc6e882618c01d8fc891214c481ab9a3788dfe38dd5e37fd1d5fb2e8"},
"ranch": {:hex, :ranch, "1.8.0", "8c7a100a139fd57f17327b6413e4167ac559fbc04ca7448e9be9057311597a1d", [:make, :rebar3], [], "hexpm", "49fbcfd3682fab1f5d109351b61257676da1a2fdbe295904176d5e521a2ddfe5"},
"slugger": {:hex, :slugger, "0.3.0", "efc667ab99eee19a48913ccf3d038b1fb9f165fa4fbf093be898b8099e61b6ed", [:mix], [], "hexpm", "20d0ded0e712605d1eae6c5b4889581c3460d92623a930ddda91e0e609b5afba"},