defmodule SomethingErlangWeb.PageController do use SomethingErlangWeb, :controller def home(conn, params) do # The home page is often custom made, # so skip the default app layout. conn = assign(conn, :params, params) render(conn, :home) end def to_forum_path(conn, %{"forum_path" => path} = _params) do {redirect_good, thread, page} = case { Regex.run(~r{threadid=(\d+)}, path), Regex.run(~r{pagenumber=(\d+)}, path) } do {[_, thread], nil} -> {:ok, thread, 1} {[_, thread], [_, page]} -> {:ok, thread, page} _ -> {:error, nil, nil} end if redirect_good == :ok do redirect(conn, to: ~p"/thread/#{thread}?page=#{page}") else put_flash(conn, :error, "Could not resolve URL") render(conn, :home) end end def to_forum_path(conn, params) do render(conn, :home) end end