-
-
Notifications
You must be signed in to change notification settings - Fork 159
Expand file tree
/
Copy pathsitemap_controller.ex
More file actions
67 lines (56 loc) · 1.46 KB
/
sitemap_controller.ex
File metadata and controls
67 lines (56 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
defmodule PlexusWeb.SitemapController do
use PlexusWeb, :controller
def index(conn, _params) do
conn
|> put_resp_content_type("text/xml")
|> put_layout(false)
|> render("sitemap.xml", routes: routes())
end
defp routes do
base_url = PlexusWeb.Endpoint.url()
PlexusWeb.Router
|> Phoenix.Router.routes()
|> Enum.reduce([], fn
%{verb: :get, path: path}, acc ->
if String.starts_with?(path, "/admin") or
String.starts_with?(path, "/api") or
String.contains?(path, ":") or
String.ends_with?(path, ".xml") do
acc
else
[build_route(base_url, path) | acc]
end
_route, acc ->
acc
end)
end
defp build_route(base_url, path) do
%{
path: full_path(base_url, path),
priority: priority(path),
change_freq: change_freq(path),
last_mod: last_mod(path)
}
end
defp full_path(base_url, path) do
path =
case path do
"/" -> "/"
path -> path <> "/"
end
base_url
|> URI.new!()
|> URI.append_path(path)
|> URI.to_string()
end
defp priority("/"), do: 1.0
defp priority(_path), do: 0.5
defp change_freq("/swaggerui"), do: "yearly"
defp change_freq(_), do: "weekly"
defp last_mod(path) when path in ["/", "/apps"] do
Plexus.Apps.fetch_most_recently_added_app!()
|> Map.fetch!(:inserted_at)
|> DateTime.to_date()
end
defp last_mod(_), do: false
end