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.
jackyalcine 3 months ago
parent
commit
ccd40a31e9
Signed by: Jacky Alciné <yo@jacky.wtf> GPG Key ID: 537A4F904B15268D

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

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

+ 2
- 1
lib/post.ex View File

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

+ 1
- 1
mix.exs View File

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

+ 2
- 2
mix.lock View File

@@ -22,7 +22,7 @@
22 22
   "cowlib": {:hex, :cowlib, "2.7.3", "a7ffcd0917e6d50b4d5fb28e9e2085a0ceb3c97dea310505f7460ff5ed764ce9", [:rebar3], [], "hexpm"},
23 23
   "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"},
24 24
   "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"},
25
-  "decimal": {:hex, :decimal, "1.7.0", "30d6b52c88541f9a66637359ddf85016df9eb266170d53105f02e4a67e00c5aa", [:mix], [], "hexpm"},
25
+  "decimal": {:hex, :decimal, "1.8.0", "ca462e0d885f09a1c5a342dbd7c1dcf27ea63548c65a65e67334f4b61803822e", [:mix], [], "hexpm"},
26 26
   "dialyxir": {:hex, :dialyxir, "1.0.0-rc.6", "78e97d9c0ff1b5521dd68041193891aebebce52fc3b93463c0a6806874557d7d", [:mix], [{:erlex, "~> 0.2.1", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm"},
27 27
   "distillery": {:hex, :distillery, "2.0.14", "25fc1cdad06282334dbf4a11b6e869cc002855c4e11825157498491df2eed594", [:mix], [{:artificery, "~> 0.2", [hex: :artificery, repo: "hexpm", optional: false]}], "hexpm"},
28 28
   "double": {:hex, :double, "0.6.6", "2280fa0800dd582ec1c542bc3aba134950bebf9281e847ecf8f50ddf19da830c", [:mix], [], "hexpm"},
@@ -47,7 +47,7 @@
47 47
   "exactor": {:hex, :exactor, "2.2.4", "5efb4ddeb2c48d9a1d7c9b465a6fffdd82300eb9618ece5d34c3334d5d7245b1", [:mix], [], "hexpm"},
48 48
   "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"},
49 49
   "exjsx": {:hex, :exjsx, "4.0.0", "60548841e0212df401e38e63c0078ec57b33e7ea49b032c796ccad8cde794b5c", [:mix], [{:jsx, "~> 2.8.0", [hex: :jsx, repo: "hexpm", optional: false]}], "hexpm"},
50
-  "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"},
50
+  "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"},
51 51
   "exredis": {:hex, :exredis, "0.3.0", "2530d9d8d5a98c5bc80bf7a14e15440a88abd6457618682f10851e39ebdd518b", [:mix], [{:eredis, ">= 1.0.8", [hex: :eredis, repo: "hexpm", optional: false]}], "hexpm"},
52 52
   "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"},
53 53
   "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 @@
1
-<div class="flex flex-row flex-wrap justify-between items-center mv2 w-auto mw7 center">
2
-  {% for photo in entry.json.photo %}
3
-    {% if forloop.first %}
1
+{% assign photo_count = entry.json.photo|size %}
2
+{% assign video_count = entry.json.video|size %}
3
+{% unless photo_count == 1 and video_count == 1 %}
4
+  <div class="flex flex-row flex-wrap justify-between items-center mv2 w-auto mw7 center">
5
+    {% for photo in entry.json.photo %}
4 6
       {% assign img_class = "w-100 self-top" %}
5 7
     {% else %}
6 8
       {% assign img_class = "w-30" %}
@@ -9,4 +11,5 @@
9 11
       <img alt="{{ photo.alt }}" class="u-photo" src="{{ photo.uri.original || photo.path }}" />
10 12
     </picture>
11 13
   {% endfor %}
12
-</div>
14
+  </div>
15
+{% endunless %}

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

@@ -2,13 +2,14 @@
2 2
 {% assign media_count = media|size %}
3 3
 <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">
4 4
     {% if media_count == 1 %}
5
-      {% assign photo = media|first %}
6
-      <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 }}">
7
-        <source src="{{ photo.uri.original }}">
5
+      {% assign video = media|first %}
6
+      {% assign poster_url = entry.json.photo[0].uri.original %}
7
+      <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 }}">
8
+        <source src="{{ video.uri.original }}">
8 9
       </video>
9 10
     {% else %}
10 11
       {% for unit in media %}
11
-      <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 %}"
12
+      <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 %}"
12 13
                alt="{{ unit.alt }}" title="{{ unit.alt }}" />
13 14
         <source src="{{ unit.uri.original }}">
14 15
       </video>

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

@@ -2,29 +2,24 @@
2 2
   {% assign prefix_name = "Bookmarked" %}
3 3
   {% assign reaction_class = "u-bookmark-of" %}
4 4
   {% render name=stream/_reaction.html %}
5
-  {% render name=stream/_reaction-media.html %}
6 5
 {% endfor %}
7 6
 {% for reaction in entry.json["repost-of"] %}
8 7
   {% assign prefix_name = "Shared" %}
9 8
   {% assign reaction_class = "u-repost-of" %}
10 9
   {% render name=stream/_reaction.html %}
11
-  {% render name=stream/_reaction-media.html %}
12 10
 {% endfor %}
13 11
 {% for reaction in entry.json["like-of"] %}
14 12
   {% assign prefix_name = "Liked" %}
15 13
   {% assign reaction_class = "u-like-of" %}
16 14
   {% render name=stream/_reaction.html %}
17
-  {% render name=stream/_reaction-media.html %}
18 15
 {% endfor %}
19 16
 {% for reaction in entry.json["in-reply-to"] %}
20 17
   {% assign prefix_name = "Replied to" %}
21 18
   {% assign reaction_class = "u-in-reply-to" %}
22 19
   {% render name=stream/_reaction.html %}
23
-  {% render name=stream/_reaction-media.html %}
24 20
 {% endfor %}
25 21
 {% for reaction in entry.json["checkin"] %}
26 22
   {% assign prefix_name = "Checked in At" %}
27 23
   {% assign reaction_class = "u-checkin" %}
28 24
   {% render name=stream/_reaction.html %}
29
-  {% render name=stream/_reaction-media.html %}
30 25
 {% endfor %}

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

@@ -1,28 +1,38 @@
1
-{% if reaction["photo"] %}
2
-  <div class="flex flex-row flex-wrap justify-between items-center mb2 w-100">
3
-    {% for photo in reaction.photo %}
4
-      {% if forloop.first %}
5
-        {% assign img_class = "w-100 self-top" %}
6
-      {% else %}
7
-        {% assign img_class = "w-30" %}
8
-      {% endif %}
9
-      <picture>
10
-        <img class="u-photo mw6 {{ img_class }}" src="{{ photo }}" />
11
-      </picture>
12
-    {% endfor %}
13
-  </div>
14
-{% endif %}
15
-{% if reaction["video"] %}
1
+{% assign photo_count = reaction.photo|size %}
2
+{% assign video_count = reaction.video|size %}
3
+{% unless photo_count == 1 and video_count == 1 %}
4
+  {% if reaction["photo"] %}
5
+    <div class="flex flex-row flex-wrap justify-between items-center mb2 w-100">
6
+      {% for photo in reaction.photo %}
7
+        {% if forloop.first %}
8
+          {% assign img_class = "w-100 self-top" %}
9
+        {% else %}
10
+          {% assign img_class = "w-30" %}
11
+        {% endif %}
12
+        <picture>
13
+          <img class="u-photo mw6 {{ img_class }}" src="{{ photo }}" />
14
+        </picture>
15
+      {% endfor %}
16
+    </div>
17
+  {% endif %}
18
+  {% if reaction["video"] %}
19
+    <div class="flex flex-row flex-wrap justify-center mb2 w-100">
20
+      {% for video in reaction.video %}
21
+        {% if forloop.first %}
22
+          {% assign vid_class = "w-100 self-top" %}
23
+        {% else %}
24
+          {% assign vid_class = "w-40 self-center ma1" %}
25
+        {% endif %}
26
+        <video controls class="{{ vid_class }}">
27
+          <source class="u-video" src="{{ video }}" />
28
+        </video>
29
+      {% endfor %}
30
+    </div>
31
+  {% endif %}
32
+{% else %}
16 33
   <div class="flex flex-row flex-wrap justify-center mb2 w-100">
17
-    {% for video in reaction.video %}
18
-      {% if forloop.first %}
19
-        {% assign vid_class = "w-100 self-top" %}
20
-      {% else %}
21
-        {% assign vid_class = "w-40 self-center ma1" %}
22
-      {% endif %}
23
-      <video controls class="{{ vid_class }}">
24
-        <source class="u-video" src="{{ video }}" />
25
-      </video>
26
-    {% endfor %}
34
+    <video controls class="w-100 self-top">
35
+      <source class="u-video" poster="{{ reaction["photo"]|first }}" src="{{ reaction["video"]|first }}" />
36
+    </video>
27 37
   </div>
28
-{% endif %}
38
+{% endunless %}

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

@@ -35,6 +35,7 @@
35 35
       <a class="u-url link underline" href="{{ reaction.url }}"> post</a>
36 36
     {% endif %}
37 37
   </header>
38
+  {% render name=stream/_reaction-media.html %}
38 39
   {% if reaction.summary %}
39 40
     <main class="e-summary br2 br--bottom mb2 pa2 f5 lh-copy">{{ reaction.summary }}</main>
40 41
   {% 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
194 194
                    :ok
195 195
                  )
196 196
 
197
+        Apex.ap [:html, html]
198
+
197 199
         assert {"x-koype-theme", unquote(template_name)} in resp.resp_headers
198 200
         assert mf2 = Microformats2.parse(html, entry_url)
199 201
         entry_mf2 = Enum.find(mf2[:items], fn entry -> "h-entry" in entry[:type] end)
@@ -213,7 +215,6 @@ defmodule Koype.Integration.TemplateTest do
213 215
 
214 216
         assert mf2_name
215 217
         assert expected_mf2_content in mf2_content
216
-        Apex.ap([entry_mf2, entry_json])
217 218
         assert Map.has_key?(entry_mf2[:properties], :photo)
218 219
       end
219 220
 

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

@@ -69,7 +69,7 @@ defmodule Koype.Web.Indie.MicropubController do
69 69
       [{:ok, path}, module] ->
70 70
         Logger.info("Uploaded #{file.filename} as #{path}")
71 71
 
72
-        uri = module.path({path, :floating})
72
+        uri = Koype.host() <> "/" <> module.path({path, :floating})
73 73
         Logger.info("#{file.filename} now has a canonical URI at #{uri}")
74 74
 
75 75
         conn
@@ -77,14 +77,14 @@ defmodule Koype.Web.Indie.MicropubController do
77 77
         |> put_status(:created)
78 78
         |> text("")
79 79
 
80
-      [{:error, error}, _module] ->
81
-        Logger.error("Failed to upload #{file.filename}: #{inspect(error)}")
80
+      [{:error, error}, module] ->
81
+        Logger.error("Failed to upload file.", filename: file.filename, error: inspect(error), module: module)
82 82
 
83 83
         conn
84 84
         |> Explode.bad_request("Could not upload provided file.")
85 85
 
86 86
       {:error, :invalid_file_type} ->
87
-        Logger.error("Failed to handle file upload for #{file.filename} of type #{content_type}")
87
+        Logger.error("Failed to handle file upload.", filename: file.filename, content_type: content_type)
88 88
 
89 89
         conn
90 90
         |> Explode.bad_request("Could not upload invalid file of #{content_type}.")
@@ -156,3 +156,5 @@ defmodule Koype.Web.Indie.MicropubController do
156 156
     end)
157 157
   end
158 158
 end
159
+
160
+

Loading…
Cancel
Save