Browse Source

fix(page): More visible output about parsing.

* Fix up template for photo rendering
* Show  more info on failures in rendering.
jackyalcine 3 months ago
parent
commit
b39a651d7e
Signed by: Jacky Alciné <yo@jacky.wtf> GPG Key ID: 537A4F904B15268D

+ 1
- 1
.lvimrc View File

@@ -8,7 +8,7 @@ if exists(':DirenvExport')
8 8
 endif
9 9
 
10 10
 let s:command_prefix = 'docker-compose run ' .
11
-      \ '-e CANONICAL_URL="http://koype_vim_test" '.
11
+      \ '-e CANONICAL_URL="http://koype_vim_test:50505" '.
12 12
       \ '-e MIX_ENV="test" ' .
13 13
       \ '-e PORT=50505 ' .
14 14
       \ '-e DOC=1 ' .

+ 11
- 4
lib/page/parser.ex View File

@@ -88,15 +88,22 @@ defmodule Koype.Page.Parser do
88 88
   @doc "Walk through all available parsers."
89 89
   def resolve(url) do
90 90
     case do_utilize_preferred_parser(url) do
91
-      {:ok, _} = result -> result
92
-      _ -> do_run_gambit_of_parsers(url)
91
+      {:ok, _} = result ->
92
+        result
93
+
94
+      _ ->
95
+        do_run_gambit_of_parsers(url)
93 96
     end
94 97
   end
95 98
 
96 99
   def do_utilize_preferred_parser(url) do
97 100
     case preferred_parser_for_url(url) do
98
-      {:ok, nil} -> {:error, :no_preferred_parser}
99
-      {:ok, parser} -> do_run_parser(parser, url)
101
+      {:ok, nil} ->
102
+        {:error, :no_preferred_parser}
103
+
104
+      {:ok, parser} ->
105
+        Logger.info("Using preferred parser.", url: url, parser: parser)
106
+        do_run_parser(parser, url)
100 107
     end
101 108
   end
102 109
 

+ 8
- 1
lib/post.ex View File

@@ -148,7 +148,14 @@ 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
-            exact_name = if is_binary(name) do name else name[:text] end
151
+
152
+            exact_name =
153
+              if is_binary(name) do
154
+                name
155
+              else
156
+                name[:text]
157
+              end
158
+
152 159
             "'" <> String.trim(exact_name) <> "'"
153 160
 
154 161
           Map.has_key?(response_props, "author") ->

+ 3
- 0
lib/template/render.ex View File

@@ -118,6 +118,9 @@ defmodule Koype.Template.Renderer do
118 118
         rescue
119 119
           e in Liquid.SyntaxError ->
120 120
             {:error, error: :fetch_template_failed, reason: e, path: theme_file_path}
121
+
122
+          e ->
123
+            {:error, :error, :unexpected_error, reason: e, path: theme_file_path}
121 124
         end
122 125
 
123 126
       {:error, err} ->

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

@@ -3,6 +3,7 @@
3 3
 {% unless photo_count == 1 and video_count == 1 %}
4 4
   <div class="flex flex-row flex-wrap justify-between items-center mv2 w-auto mw7 center">
5 5
     {% for photo in entry.json.photo %}
6
+    {% if forloop.first == true %}
6 7
       {% assign img_class = "w-100 self-top" %}
7 8
     {% else %}
8 9
       {% assign img_class = "w-30" %}

+ 59
- 0
test/integration/controllers/indie/micropub_controller_test.exs View File

@@ -2,6 +2,7 @@ defmodule Koype.Web.Indie.MicropubControllerTest do
2 2
   use Koype.Test.BaseCase, async: false
3 3
   use Koype.Web.ConnCase
4 4
   use Koype.DataCase
5
+  alias Koype.Repo.Entry, as: Model
5 6
   import Koype.Factory
6 7
   import Mock
7 8
   import Double
@@ -106,6 +107,64 @@ defmodule Koype.Web.Indie.MicropubControllerTest do
106 107
       assert conn |> get_resp_header("location") |> List.first() =~ "/post/"
107 108
     end
108 109
 
110
+    test "201 creates a new reply using JSON" do
111
+      entry = insert(:entry, visibility: "public")
112
+      entry_json = build(:entry_json)
113
+      Model.json_persist(entry, entry_json)
114
+      entry_uri = Model.get_uri(entry)
115
+
116
+      conn =
117
+        build_conn()
118
+        |> indie_sign_in_conn(@client_id, ~w(create))
119
+        |> put_req_header("content-type", "application/json")
120
+        |> post(@route, %{
121
+          "type" => "entry",
122
+          "properties" => %{
123
+            "in-reply-to" => [entry_uri],
124
+            "content" => Faker.Lorem.paragraph()
125
+          }
126
+        })
127
+        |> doc(
128
+          description: "Creates a new entry with JSON that replies to a post",
129
+          operation_id: "micropub_json_reply"
130
+        )
131
+
132
+      assert text_response(conn, :created)
133
+      assert conn |> get_resp_header("location") |> List.first() =~ "/post/"
134
+    end
135
+
136
+    test "201 creates a new reply to a phtoo post using JSON" do
137
+      entry = insert(:entry, visibility: "public", type: "photo")
138
+
139
+      {:ok, entry_json} =
140
+        build(:entry_json)
141
+        |> with_html_content
142
+        |> with_post_type(:single_photo)
143
+        |> IndieWeb.Micropub.Entry.process_properties()
144
+
145
+      {:ok, _} = Koype.Repo.Entry.json_persist(entry, entry_json)
146
+      entry_url = Koype.Repo.Entry.get_uri(entry)
147
+
148
+      conn =
149
+        build_conn()
150
+        |> indie_sign_in_conn(@client_id, ~w(create))
151
+        |> put_req_header("content-type", "application/json")
152
+        |> post(@route, %{
153
+          "type" => "entry",
154
+          "properties" => %{
155
+            "in-reply-to" => [entry_url],
156
+            "content" => Faker.Lorem.paragraph()
157
+          }
158
+        })
159
+        |> doc(
160
+          description: "Creates a new entry with JSON that replies to a post",
161
+          operation_id: "micropub_json_reply"
162
+        )
163
+
164
+      assert text_response(conn, :created)
165
+      assert conn |> get_resp_header("location") |> List.first() =~ "/post/"
166
+    end
167
+
109 168
     test "201 creates a new entry json with emoji" do
110 169
       conn =
111 170
         build_conn()

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

@@ -194,7 +194,7 @@ defmodule Koype.Integration.TemplateTest do
194 194
                    :ok
195 195
                  )
196 196
 
197
-        Apex.ap [:html, html]
197
+        Apex.ap([:html, html])
198 198
 
199 199
         assert {"x-koype-theme", unquote(template_name)} in resp.resp_headers
200 200
         assert mf2 = Microformats2.parse(html, entry_url)

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

@@ -78,13 +78,20 @@ defmodule Koype.Web.Indie.MicropubController do
78 78
         |> text("")
79 79
 
80 80
       [{:error, error}, module] ->
81
-        Logger.error("Failed to upload file.", filename: file.filename, error: inspect(error), module: module)
81
+        Logger.error("Failed to upload file.",
82
+          filename: file.filename,
83
+          error: inspect(error),
84
+          module: module
85
+        )
82 86
 
83 87
         conn
84 88
         |> Explode.bad_request("Could not upload provided file.")
85 89
 
86 90
       {:error, :invalid_file_type} ->
87
-        Logger.error("Failed to handle file upload.", filename: file.filename, content_type: content_type)
91
+        Logger.error("Failed to handle file upload.",
92
+          filename: file.filename,
93
+          content_type: content_type
94
+        )
88 95
 
89 96
         conn
90 97
         |> Explode.bad_request("Could not upload invalid file of #{content_type}.")
@@ -156,5 +163,3 @@ defmodule Koype.Web.Indie.MicropubController do
156 163
     end)
157 164
   end
158 165
 end
159
-
160
-

Loading…
Cancel
Save