<commit_before>module Servant.Utils.StaticFiles (
  serveDirectory,
  serveDocumentation,
 ) where

import Data.Proxy
import Data.String.Conversions
import Filesystem.Path.CurrentOS (decodeString)
import Network.HTTP.Types
import Network.Wai
import Network.Wai.Application.Static

import Servant.API
import Servant.Docs
import Servant.Server

serveDirectory :: FilePath -> Server Raw
serveDirectory documentRoot =
  staticApp (defaultFileServerSettings (decodeString (documentRoot ++ "/")))

serveDocumentation :: HasDocs api => Proxy api -> Server Raw
serveDocumentation proxy _request respond =
  respond $ responseLBS ok200 [] $ cs $ toHtml $ markdown $ docs proxy

toHtml :: String -> String
toHtml markdown =
  "<html>" ++
  "<body>" ++
  "<verbatim>" ++
  markdown ++
  "</verbatim>" ++
  "</body>" ++<commit_msg>html's verbatim is called pre<commit_after>module Servant.Utils.StaticFiles (
  serveDirectory,
  serveDocumentation,
 ) where

import Data.Proxy
import Data.String.Conversions
import Filesystem.Path.CurrentOS (decodeString)
import Network.HTTP.Types
import Network.Wai
import Network.Wai.Application.Static

import Servant.API
import Servant.Docs
import Servant.Server

serveDirectory :: FilePath -> Server Raw
serveDirectory documentRoot =
  staticApp (defaultFileServerSettings (decodeString (documentRoot ++ "/")))

serveDocumentation :: HasDocs api => Proxy api -> Server Raw
serveDocumentation proxy _request respond =
  respond $ responseLBS ok200 [] $ cs $ toHtml $ markdown $ docs proxy

toHtml :: String -> String
toHtml markdown =
  "<html>" ++
  "<body>" ++
  "<pre>" ++
  markdown ++
  "</pre>" ++
  "</body>" ++
{'fraction_non_alphanumeric': 0.11496350364963503, 'fraction_numerical': 0.0036496350364963502, 'mean_word_length': 4.896057347670251, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 21, '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': '7036926', 'n_tokens_mistral': 483, 'n_tokens_neox': 476, 'n_words': 132}