home73k/lib/home73k_web/controllers/home_controller.ex

45 lines
980 B
Elixir
Raw Normal View History

2021-03-29 19:50:47 -04:00
defmodule Home73kWeb.HomeController do
use Home73kWeb, :controller
def index(conn, _params) do
render(conn, "index.html")
end
2021-04-03 23:22:35 -04:00
def about(conn, _params) do
render(conn, "about.html", page_title: "About")
end
2021-03-29 19:50:47 -04:00
def resume(conn, _params) do
render(conn, "resume.html", page_title: "Résumé")
end
def folio(conn, _params) do
render(conn, "folio.html", page_title: "Folio")
end
@valid_codes [400..418, 421..426, 428..429, 500..508]
|> Enum.map(&Enum.to_list/1)
|> Enum.concat()
|> Enum.concat([431, 451, 510, 511])
def err(conn, params) do
code = Map.get(params, "code", "404") |> err_code_as_int()
code = code in @valid_codes && code || 404
conn
|> put_status(code)
|> put_layout(false)
|> put_root_layout(false)
|> put_view(Home73kWeb.ErrorView)
|> render("#{code}.html")
end
defp err_code_as_int(code) do
try do
String.to_integer(code)
rescue
_ -> 404
end
end
2021-03-29 19:50:47 -04:00
end