• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

curt / revix / 9e8c0bc360c2469b897a151b8fac1bcb73dda05a

18 May 2026 12:01PM UTC coverage: 92.24% (+0.4%) from 91.834%
9e8c0bc360c2469b897a151b8fac1bcb73dda05a

push

github

curt
chore: improve coverage with additional unit tests

3233 of 3505 relevant lines covered (92.24%)

178.57 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.75
/lib/revix_web/structured_data.ex
1
defmodule RevixWeb.StructuredData do
2
  alias Revix.Places.Place
3
  alias RevixWeb.CanonicalRoutes
4

5
  def place_og(%Place{} = place) do
6
    [{"og:type", "place"}, {"og:title", place.name}, {"og:url", CanonicalRoutes.place_url(place)}]
33✔
7
    |> maybe_append("og:description", place.content)
33✔
8
  end
9

10
  def checkin_og(%Revix.Entries.Entry{} = checkin) do
11
    [
12
      {"og:type", "article"},
13
      {"og:title", checkin_name(checkin.place)},
30✔
14
      {"og:url", CanonicalRoutes.checkin_url(checkin)}
15
    ]
16
    |> maybe_append("og:description", checkin.content)
30✔
17
    |> maybe_append("og:image", first_image_url(checkin.entry_images))
30✔
18
  end
19

20
  def post_og(%Revix.Entries.Entry{} = post) do
21
    [{"og:type", "article"}, {"og:url", CanonicalRoutes.post_url(post)}]
22
    |> maybe_append("og:title", post.name)
30✔
23
    |> maybe_append("og:description", post.summary)
30✔
24
    |> maybe_append("og:image", first_image_url(post.entry_images))
30✔
25
  end
26

27
  def place_json_ld(%Place{} = place) do
28
    %{
29
      "@context" => "https://schema.org",
30
      "@type" => "TouristAttraction",
31
      "name" => place.name,
35✔
32
      "url" => CanonicalRoutes.place_url(place)
33
    }
34
    |> maybe_put("geo", geo_coordinates(place.coordinates))
35✔
35
    |> maybe_put("sameAs", osm_url(place))
35✔
36
  end
37

38
  def checkin_json_ld(%Revix.Entries.Entry{} = checkin) do
39
    %{
40
      "@context" => "https://schema.org",
41
      "@type" => "Event",
42
      "name" => checkin_name(checkin.place),
37✔
43
      "startDate" => DateTime.to_iso8601(checkin.starts_at_utc),
37✔
44
      "url" => CanonicalRoutes.checkin_url(checkin)
45
    }
46
    |> maybe_put("location", place_location(checkin.place))
37✔
47
    |> maybe_put("organizer", author_person(checkin.author))
37✔
48
  end
49

50
  def post_json_ld(%Revix.Entries.Entry{published_at_utc: nil}), do: nil
×
51

52
  def post_json_ld(%Revix.Entries.Entry{} = post) do
53
    %{
54
      "@context" => "https://schema.org",
55
      "@type" => "BlogPosting",
56
      "datePublished" => DateTime.to_iso8601(post.published_at_utc),
35✔
57
      "url" => CanonicalRoutes.post_url(post)
58
    }
59
    |> maybe_put("headline", post.name)
35✔
60
    |> maybe_put("author", author_person(post.author))
35✔
61
    |> maybe_put("description", post.summary)
35✔
62
    |> maybe_put("contentLocation", post_locations(post.entry_places))
35✔
63
  end
64

65
  defp geo_coordinates(%Geo.Point{coordinates: {lon, lat}}) do
66
    %{"@type" => "GeoCoordinates", "latitude" => lat, "longitude" => lon}
73✔
67
  end
68

69
  defp geo_coordinates(_), do: nil
2✔
70

71
  defp place_location(%Place{} = place) do
72
    %{"@type" => "Place", "name" => place.name}
40✔
73
    |> maybe_put("geo", geo_coordinates(place.coordinates))
40✔
74
    |> maybe_put("sameAs", osm_url(place))
40✔
75
  end
76

77
  defp place_location(nil), do: nil
2✔
78

79
  defp post_locations([]), do: nil
31✔
80

81
  defp post_locations(entry_places) do
82
    Enum.map(entry_places, fn ep -> place_location(ep.place) end)
4✔
83
  end
84

85
  defp checkin_name(%Place{name: name}), do: "Checkin at #{name}"
64✔
86
  defp checkin_name(nil), do: "Checkin"
3✔
87

88
  defp author_person(%{display_name: name, url: url}) when is_binary(name) and name != "" do
89
    %{"@type" => "Person", "name" => name}
90
    |> maybe_put("url", url)
22✔
91
  end
92

93
  defp author_person(%{username: username, url: url})
94
       when is_binary(username) and username != "" do
95
    %{"@type" => "Person", "name" => username}
96
    |> maybe_put("url", url)
3✔
97
  end
98

99
  defp author_person(_), do: nil
47✔
100

101
  defp osm_url(%Place{osm_type: osm_type, osm_id: osm_id})
102
       when not is_nil(osm_type) and not is_nil(osm_id) do
103
    "https://www.openstreetmap.org/#{osm_type}/#{osm_id}"
5✔
104
  end
105

106
  defp osm_url(_), do: nil
70✔
107

108
  defp first_image_url([]), do: nil
55✔
109
  defp first_image_url([ei | _]), do: image_url(ei.image)
5✔
110

111
  defp image_url(image) do
112
    case Revix.Uploaders.Image.url({image.file, image}, :large) do
5✔
113
      "//" <> _ = url -> url
×
114
      "/" <> _ = path -> Phoenix.VerifiedRoutes.unverified_url(RevixWeb.Endpoint, path)
5✔
115
      url -> url
×
116
    end
117
  end
118

119
  defp maybe_append(list, _key, nil), do: list
146✔
120
  defp maybe_append(list, _key, ""), do: list
1✔
121
  defp maybe_append(list, key, value), do: list ++ [{key, value}]
36✔
122

123
  defp maybe_put(map, _key, nil), do: map
190✔
124
  defp maybe_put(map, _key, ""), do: map
1✔
125
  defp maybe_put(map, key, value), do: Map.put(map, key, value)
198✔
126
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc