defmodule ToweropsWeb.Plugs.MarkdownNegotiation do @moduledoc false import Plug.Conn @markdown_content %{ "/" => """ # TowerOps Network monitoring and alerting platform built for WISP and ISP operators. See the business impact of every network event. ## Features - Real-time network monitoring - Subscriber impact analysis - Revenue impact tracking - Equipment management - Multi-site support ## Get Started - [Register](/users/register) - [Log In](/users/log-in) - [API Documentation](/docs/api) - [Privacy Policy](/privacy) - [Terms of Service](/terms) """, "/privacy" => "# Privacy Policy\n\nVisit [towerops.net/privacy](https://towerops.net/privacy) for the full privacy policy.\n", "/terms" => "# Terms of Service\n\nVisit [towerops.net/terms](https://towerops.net/terms) for the full terms of service.\n" } def init(opts), do: opts def call(conn, _opts) do if accepts_markdown?(conn) do case Map.get(@markdown_content, conn.request_path) do nil -> conn markdown -> send_markdown(conn, markdown) end else conn end end defp accepts_markdown?(conn) do conn |> get_req_header("accept") |> Enum.any?(&String.contains?(&1, "text/markdown")) end defp send_markdown(conn, content) do conn |> put_resp_content_type("text/markdown") |> send_resp(200, content) |> halt() end end