Browse Source

fix(reply): Move media into header.

This moves the media in a reply post into the reply context such that
the media is not associated with the base content.
tags/v0.0.16^2
jackyalcine 7 months ago
parent
commit
ccd40a31e9
Signed by: me <yo@jacky.wtf> GPG Key ID: 537A4F904B15268D
11 changed files with 63 additions and 48 deletions
  1. +1
    -0
      lib/mix/tasks/koype/seed_environment.ex
  2. +2
    -1
      lib/post.ex
  3. +1
    -1
      mix.exs
  4. +2
    -2
      mix.lock
  5. +7
    -4
      priv/themes/default/tmpl/entry/type/media/photo.html.liquid
  6. +5
    -4
      priv/themes/default/tmpl/entry/type/media/video.html.liquid
  7. +0
    -5
      priv/themes/default/tmpl/stream/_reaction-header.html.liquid
  8. +36
    -26
      priv/themes/default/tmpl/stream/_reaction-media.html.liquid
  9. +1
    -0
      priv/themes/default/tmpl/stream/_reaction.html.liquid
  10. +2
    -1
      test/integration/template_test.exs
  11. +6
    -4
      web/controllers/indie/micropub_controller.ex

+ 1
- 0
lib/mix/tasks/koype/seed_environment.ex View File

@@ -19,6 +19,7 @@ defmodule Mix.Tasks.Koype.SeedEnv do
],
[args: %{"like-of" => ["https://v2.jacky.wtf/post/0f88aa8d-4bd7-4455-b130-7b90836f9e94"]}],
[args: %{"like-of" => ["https://aaronparecki.com/2019/06/08/10/"]}],
[args: %{"like-of" => ["https://playvicious.social/@jalcine/102390679008364376"]}],
[args: %{"like-of" => ["https://aaronparecki.com/2019/05/27/36/"], "location" => %{}}],
[args: %{"repost-of" => ["https://v2.jacky.wtf"]}],
[args: %{"bookmark-of" => ["https://indieweb.org"]}],


+ 2
- 1
lib/post.ex View File

@@ -148,7 +148,8 @@ defmodule Koype.Post do
cond do
Map.has_key?(response_props, "name") ->
name = Map.get(response_props, "name") |> List.wrap() |> List.first()
"'" <> String.trim(name) <> "'"
exact_name = if is_binary(name) do name else name[:text] end
"'" <> String.trim(exact_name) <> "'"

Map.has_key?(response_props, "author") ->
author_name =


+ 1
- 1
mix.exs View File

@@ -101,7 +101,7 @@ defmodule Koype.Mixfile do
{:ex_machina, "~> 2.2", only: :test},
{:ex_url, "~> 1.0.0"},
{:excoveralls, "~> 0.8", only: :test},
{:explode, "~> 1.0.0"},
{:explode, "~> 1.1.0"},
{:exvcr, "~> 0.10", only: :test},
{:faker, "~> 0.12.0", only: [:test, :dev]},
{:floki, "~> 0.20.0", override: true},


+ 2
- 2
mix.lock View File

@@ -22,7 +22,7 @@
"cowlib": {:hex, :cowlib, "2.7.3", "a7ffcd0917e6d50b4d5fb28e9e2085a0ceb3c97dea310505f7460ff5ed764ce9", [:rebar3], [], "hexpm"},
"credo": {:hex, :credo, "0.10.2", "03ad3a1eff79a16664ed42fc2975b5e5d0ce243d69318060c626c34720a49512", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm"},
"db_connection": {:hex, :db_connection, "1.1.3", "89b30ca1ef0a3b469b1c779579590688561d586694a3ce8792985d4d7e575a61", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: true]}], "hexpm"},
"decimal": {:hex, :decimal, "1.7.0", "30d6b52c88541f9a66637359ddf85016df9eb266170d53105f02e4a67e00c5aa", [:mix], [], "hexpm"},
"decimal": {:hex, :decimal, "1.8.0", "ca462e0d885f09a1c5a342dbd7c1dcf27ea63548c65a65e67334f4b61803822e", [:mix], [], "hexpm"},
"dialyxir": {:hex, :dialyxir, "1.0.0-rc.6", "78e97d9c0ff1b5521dd68041193891aebebce52fc3b93463c0a6806874557d7d", [:mix], [{:erlex, "~> 0.2.1", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm"},
"distillery": {:hex, :distillery, "2.0.14", "25fc1cdad06282334dbf4a11b6e869cc002855c4e11825157498491df2eed594", [:mix], [{:artificery, "~> 0.2", [hex: :artificery, repo: "hexpm", optional: false]}], "hexpm"},
"double": {:hex, :double, "0.6.6", "2280fa0800dd582ec1c542bc3aba134950bebf9281e847ecf8f50ddf19da830c", [:mix], [], "hexpm"},
@@ -47,7 +47,7 @@
"exactor": {:hex, :exactor, "2.2.4", "5efb4ddeb2c48d9a1d7c9b465a6fffdd82300eb9618ece5d34c3334d5d7245b1", [:mix], [], "hexpm"},
"excoveralls": {:hex, :excoveralls, "0.11.1", "dd677fbdd49114fdbdbf445540ec735808250d56b011077798316505064edb2c", [:mix], [{:hackney, "~> 1.0", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm"},
"exjsx": {:hex, :exjsx, "4.0.0", "60548841e0212df401e38e63c0078ec57b33e7ea49b032c796ccad8cde794b5c", [:mix], [{:jsx, "~> 2.8.0", [hex: :jsx, repo: "hexpm", optional: false]}], "hexpm"},
"explode": {:hex, :explode, "1.0.0", "e9b9acae7a7fe15027a8813b19b8cd424d8747903428ed4ae13c1460aaaa2934", [:mix], [{:ecto, ">= 2.0.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:poison, "~> 2.1 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"},
"explode": {:hex, :explode, "1.1.1", "6573d58adfa0c7e37ba310b17533f967f53d4a0285b4487862fa2a137419d4c0", [:mix], [{:ecto, ">= 2.0.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:poison, "~> 2.1 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"},
"exredis": {:hex, :exredis, "0.3.0", "2530d9d8d5a98c5bc80bf7a14e15440a88abd6457618682f10851e39ebdd518b", [:mix], [{:eredis, ">= 1.0.8", [hex: :eredis, repo: "hexpm", optional: false]}], "hexpm"},
"exvcr": {:hex, :exvcr, "0.10.3", "1ae3b97560430acfa88ebc737c85b2b7a9dbacd8a2b26789a19718b51ae3522c", [:mix], [{:exactor, "~> 2.2", [hex: :exactor, repo: "hexpm", optional: false]}, {:exjsx, "~> 4.0", [hex: :exjsx, repo: "hexpm", optional: false]}, {:httpoison, "~> 1.0", [hex: :httpoison, repo: "hexpm", optional: true]}, {:httpotion, "~> 3.1", [hex: :httpotion, repo: "hexpm", optional: true]}, {:ibrowse, "~> 4.4", [hex: :ibrowse, repo: "hexpm", optional: true]}, {:meck, "~> 0.8", [hex: :meck, repo: "hexpm", optional: false]}], "hexpm"},
"faker": {:hex, :faker, "0.12.0", "796cbac868c86c2df6f273ea4cdf2e271860863820e479e04a374b7ee6c376b6", [:mix], [], "hexpm"},


+ 7
- 4
priv/themes/default/tmpl/entry/type/media/photo.html.liquid View File

@@ -1,6 +1,8 @@
<div class="flex flex-row flex-wrap justify-between items-center mv2 w-auto mw7 center">
{% for photo in entry.json.photo %}
{% if forloop.first %}
{% assign photo_count = entry.json.photo|size %}
{% assign video_count = entry.json.video|size %}
{% unless photo_count == 1 and video_count == 1 %}
<div class="flex flex-row flex-wrap justify-between items-center mv2 w-auto mw7 center">
{% for photo in entry.json.photo %}
{% assign img_class = "w-100 self-top" %}
{% else %}
{% assign img_class = "w-30" %}
@@ -9,4 +11,5 @@
<img alt="{{ photo.alt }}" class="u-photo" src="{{ photo.uri.original || photo.path }}" />
</picture>
{% endfor %}
</div>
</div>
{% endunless %}

+ 5
- 4
priv/themes/default/tmpl/entry/type/media/video.html.liquid View File

@@ -2,13 +2,14 @@
{% assign media_count = media|size %}
<main class="flex flex-column flex-row-l flex-wrap-l flex-auto flex-grow -start{% if media_count == 1 %}w-auto{% else %}w-100{% endif %} items-start order-1 self-start pa1">
{% if media_count == 1 %}
{% assign photo = media|first %}
<video controls class="w-auto br2 u-photo mv2 mv1-l bw1 ba-ns b--silver silver shadow-1" alt="{{ video.alt }}" title="{{ video.alt }}">
<source src="{{ photo.uri.original }}">
{% assign video = media|first %}
{% assign poster_url = entry.json.photo[0].uri.original %}
<video controls poster="{{ poster_url }}" class="w-auto br2 u-video mv2 mv1-l bw1 ba-ns b--silver silver shadow-1" alt="{{ video.alt }}" title="{{ video.alt }}">
<source src="{{ video.uri.original }}">
</video>
{% else %}
{% for unit in media %}
<video controls class="shadow-1 w-auto u-photo br2 mv2 {% if forloop.first %}mw7-l mv0-l bw3 bn ba-l b--silver silver{% else %}bw1 bn ba-l b--silver silver w-auto mw5-l mh1-l{% endif %}"
<video controls class="shadow-1 w-auto u-video br2 mv2 {% if forloop.first %}mw7-l mv0-l bw3 bn ba-l b--silver silver{% else %}bw1 bn ba-l b--silver silver w-auto mw5-l mh1-l{% endif %}"
alt="{{ unit.alt }}" title="{{ unit.alt }}" />
<source src="{{ unit.uri.original }}">
</video>


+ 0
- 5
priv/themes/default/tmpl/stream/_reaction-header.html.liquid View File

@@ -2,29 +2,24 @@
{% assign prefix_name = "Bookmarked" %}
{% assign reaction_class = "u-bookmark-of" %}
{% render name=stream/_reaction.html %}
{% render name=stream/_reaction-media.html %}
{% endfor %}
{% for reaction in entry.json["repost-of"] %}
{% assign prefix_name = "Shared" %}
{% assign reaction_class = "u-repost-of" %}
{% render name=stream/_reaction.html %}
{% render name=stream/_reaction-media.html %}
{% endfor %}
{% for reaction in entry.json["like-of"] %}
{% assign prefix_name = "Liked" %}
{% assign reaction_class = "u-like-of" %}
{% render name=stream/_reaction.html %}
{% render name=stream/_reaction-media.html %}
{% endfor %}
{% for reaction in entry.json["in-reply-to"] %}
{% assign prefix_name = "Replied to" %}
{% assign reaction_class = "u-in-reply-to" %}
{% render name=stream/_reaction.html %}
{% render name=stream/_reaction-media.html %}
{% endfor %}
{% for reaction in entry.json["checkin"] %}
{% assign prefix_name = "Checked in At" %}
{% assign reaction_class = "u-checkin" %}
{% render name=stream/_reaction.html %}
{% render name=stream/_reaction-media.html %}
{% endfor %}

+ 36
- 26
priv/themes/default/tmpl/stream/_reaction-media.html.liquid View File

@@ -1,28 +1,38 @@
{% if reaction["photo"] %}
<div class="flex flex-row flex-wrap justify-between items-center mb2 w-100">
{% for photo in reaction.photo %}
{% if forloop.first %}
{% assign img_class = "w-100 self-top" %}
{% else %}
{% assign img_class = "w-30" %}
{% endif %}
<picture>
<img class="u-photo mw6 {{ img_class }}" src="{{ photo }}" />
</picture>
{% endfor %}
</div>
{% endif %}
{% if reaction["video"] %}
{% assign photo_count = reaction.photo|size %}
{% assign video_count = reaction.video|size %}
{% unless photo_count == 1 and video_count == 1 %}
{% if reaction["photo"] %}
<div class="flex flex-row flex-wrap justify-between items-center mb2 w-100">
{% for photo in reaction.photo %}
{% if forloop.first %}
{% assign img_class = "w-100 self-top" %}
{% else %}
{% assign img_class = "w-30" %}
{% endif %}
<picture>
<img class="u-photo mw6 {{ img_class }}" src="{{ photo }}" />
</picture>
{% endfor %}
</div>
{% endif %}
{% if reaction["video"] %}
<div class="flex flex-row flex-wrap justify-center mb2 w-100">
{% for video in reaction.video %}
{% if forloop.first %}
{% assign vid_class = "w-100 self-top" %}
{% else %}
{% assign vid_class = "w-40 self-center ma1" %}
{% endif %}
<video controls class="{{ vid_class }}">
<source class="u-video" src="{{ video }}" />
</video>
{% endfor %}
</div>
{% endif %}
{% else %}
<div class="flex flex-row flex-wrap justify-center mb2 w-100">
{% for video in reaction.video %}
{% if forloop.first %}
{% assign vid_class = "w-100 self-top" %}
{% else %}
{% assign vid_class = "w-40 self-center ma1" %}
{% endif %}
<video controls class="{{ vid_class }}">
<source class="u-video" src="{{ video }}" />
</video>
{% endfor %}
<video controls class="w-100 self-top">
<source class="u-video" poster="{{ reaction["photo"]|first }}" src="{{ reaction["video"]|first }}" />
</video>
</div>
{% endif %}
{% endunless %}

+ 1
- 0
priv/themes/default/tmpl/stream/_reaction.html.liquid View File

@@ -35,6 +35,7 @@
<a class="u-url link underline" href="{{ reaction.url }}"> post</a>
{% endif %}
</header>
{% render name=stream/_reaction-media.html %}
{% if reaction.summary %}
<main class="e-summary br2 br--bottom mb2 pa2 f5 lh-copy">{{ reaction.summary }}</main>
{% elsif content != nil and content != empty and content != blank %}


+ 2
- 1
test/integration/template_test.exs View File

@@ -194,6 +194,8 @@ defmodule Koype.Integration.TemplateTest do
:ok
)

Apex.ap [:html, html]

assert {"x-koype-theme", unquote(template_name)} in resp.resp_headers
assert mf2 = Microformats2.parse(html, entry_url)
entry_mf2 = Enum.find(mf2[:items], fn entry -> "h-entry" in entry[:type] end)
@@ -213,7 +215,6 @@ defmodule Koype.Integration.TemplateTest do

assert mf2_name
assert expected_mf2_content in mf2_content
Apex.ap([entry_mf2, entry_json])
assert Map.has_key?(entry_mf2[:properties], :photo)
end



+ 6
- 4
web/controllers/indie/micropub_controller.ex View File

@@ -69,7 +69,7 @@ defmodule Koype.Web.Indie.MicropubController do
[{:ok, path}, module] ->
Logger.info("Uploaded #{file.filename} as #{path}")

uri = module.path({path, :floating})
uri = Koype.host() <> "/" <> module.path({path, :floating})
Logger.info("#{file.filename} now has a canonical URI at #{uri}")

conn
@@ -77,14 +77,14 @@ defmodule Koype.Web.Indie.MicropubController do
|> put_status(:created)
|> text("")

[{:error, error}, _module] ->
Logger.error("Failed to upload #{file.filename}: #{inspect(error)}")
[{:error, error}, module] ->
Logger.error("Failed to upload file.", filename: file.filename, error: inspect(error), module: module)

conn
|> Explode.bad_request("Could not upload provided file.")

{:error, :invalid_file_type} ->
Logger.error("Failed to handle file upload for #{file.filename} of type #{content_type}")
Logger.error("Failed to handle file upload.", filename: file.filename, content_type: content_type)

conn
|> Explode.bad_request("Could not upload invalid file of #{content_type}.")
@@ -156,3 +156,5 @@ defmodule Koype.Web.Indie.MicropubController do
end)
end
end



Loading…
Cancel
Save