<commit_before>defmodule Teal.Web.PageController do
  use Teal.Web, :controller
  alias Teal.Core.Document
  alias Teal.Repo
  require Logger

  plug :rate_limit,
    %{name: "create_document", max_requests: 5, interval_seconds: 60}
    when action in [:create_document]

  def index(conn, _params) do
    Logger.log :info, "rendering index page"
    changeset = Document.changeset(%Document{})
    render conn, "index.html", changeset: changeset
  end

  def about(conn, _params) do
    render conn, "about.html"
  end

  def show_document_by_slug(conn, %{"slug" => slug}) do
    Logger.log :info, "Showing document '#{slug}'"
    case Repo.get_by(Document, slug: slug) do
      nil ->
        conn
        |> put_status(404)
        |> render("404.html")
      document ->
        case Earmark.as_html(document.md_content) do
          {:ok, html, []} ->
            render conn, "document.html", document: document, document_html: html
          _ -><commit_msg>rate limit viewing of pages too<commit_after>defmodule Teal.Web.PageController do
  use Teal.Web, :controller
  alias Teal.Core.Document
  alias Teal.Repo
  require Logger

  plug :rate_limit,
    %{name: "create_document", max_requests: 5, interval_seconds: 60}
    when action in [:create_document]

  plug :rate_limit,
    %{name: "show document", max_requests: 100, interval_seconds: 60}


  def index(conn, _params) do
    Logger.log :info, "rendering index page"
    changeset = Document.changeset(%Document{})
    render conn, "index.html", changeset: changeset
  end

  def about(conn, _params) do
    render conn, "about.html"
  end

  def show_document_by_slug(conn, %{"slug" => slug}) do
    Logger.log :info, "Showing document '#{slug}'"
    case Repo.get_by(Document, slug: slug) do
      nil ->
        conn
        |> put_status(404)
        |> render("404.html")
      document ->
        case Earmark.as_html(document.md_content) do
          {:ok, html, []} ->
            render conn, "document.html", document: document, document_html: html
          _ ->
{'fraction_non_alphanumeric': 0.12058823529411765, 'fraction_numerical': 0.011274509803921568, 'mean_word_length': 3.0256410256410255, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '122579', 'n_tokens_mistral': 685, 'n_tokens_neox': 653, 'n_words': 176}