<commit_before>{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}
module ServeFile where

import Control.Monad.Trans (liftIO)
import qualified Data.List as List
import Snap.Core (Snap, writeBuilder)
import Text.Blaze.Html5 as H
import Text.Blaze.Html5.Attributes as A
import qualified Text.Blaze.Html.Renderer.Utf8 as Blaze

import qualified Elm.Compiler.Module as Module
import qualified Elm.Package as Pkg
import qualified PackageSummary as PkgSummary
import qualified Path


favicon :: H.Html
favicon =
  H.link
    ! A.rel "shortcut icon"
    ! A.size "16x16, 32x32, 48x48, 64x64, 128x128, 256x256"
    ! A.href "/assets/favicon.ico"


makeHtml :: String -> [String] -> Snap (Maybe (String, [(String, String)])) -> Snap ()
makeHtml title elmModuleName makePortInput =
  let
    elmModule =
      Module.Name elmModuleName
  in
  do  maybePortInput <- makePortInput
      writeBuilder $ Blaze.renderHtmlBuilder $ docTypeHtml $ do
        H.head $ do
          meta ! charset "UTF-8"
          favicon
          H.title (toHtml title)
          googleAnalytics
          link ! rel "stylesheet" ! href "/assets/highlight/styles/default.css"
          link ! rel "stylesheet" ! href "/assets/style.css"
          script ! src "/assets/highlight/highlight.pack.js" $ ""
          script ! src (toValue ("/" ++ Path.artifact elmModule)) $ ""

        body $
          script $ preEscapedToMarkup $
            case maybePortInput of
              Nothing ->
                "\nElm.fullscreen(Elm." ++ Module.nameToString elmModule ++ ")\n"

              Just (portName, entries) ->
                "\nvar content = { " ++ List.intercalate "," (List.map (\(k,v) -> "\n    " ++ k ++ ": " ++ v) entries) ++ "\n};\n"
                ++ "var page = Elm.fullscreen(Elm." ++ Module.nameToString elmModule ++ ", { " ++ portName ++ ": content });\n"


elm :: String -> [String] -> Snap ()
elm title elmModuleName =
  makeHtml title elmModuleName (return Nothing)

<commit_msg>Add cacheBuster for static resources<commit_after>{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}
module ServeFile where

import Control.Monad.Trans (liftIO)
import qualified Data.List as List
import Snap.Core (Snap, writeBuilder)
import Text.Blaze.Html5 as H
import Text.Blaze.Html5.Attributes as A
import qualified Text.Blaze.Html.Renderer.Utf8 as Blaze

import qualified Elm.Compiler.Module as Module
import qualified Elm.Package as Pkg
import qualified PackageSummary as PkgSummary
import qualified Path


favicon :: H.Html
favicon =
  H.link
    ! A.rel "shortcut icon"
    ! A.size "16x16, 32x32, 48x48, 64x64, 128x128, 256x256"
    ! A.href "/assets/favicon.ico"


cacheBuster :: String -> AttributeValue
cacheBuster url =
  toValue (url ++ "?1")


makeHtml :: String -> [String] -> Snap (Maybe (String, [(String, String)])) -> Snap ()
makeHtml title elmModuleName makePortInput =
  let
    elmModule =
      Module.Name elmModuleName
  in
  do  maybePortInput <- makePortInput
      writeBuilder $ Blaze.renderHtmlBuilder $ docTypeHtml $ do
        H.head $ do
          meta ! charset "UTF-8"
          favicon
          H.title (toHtml title)
          googleAnalytics
          link ! rel "stylesheet" ! href (cacheBuster "/assets/highlight/styles/default.css")
          link ! rel "stylesheet" ! href (cacheBuster "/assets/style.css")
          script ! src (cacheBuster "/assets/highlight/highlight.pack.js") $ ""
          script ! src (cacheBuster ("/" ++ Path.artifact elmModule)) $ ""

        body $
          script $ preEscapedToMarkup $
            case maybePortInput of
              Nothing ->
                "\nElm.fullscreen(Elm." ++ Module.nameToString elmModule ++ ")\n"

              Just (portName, entries) ->
                "\nvar content = { " ++ List.intercalate "," (List.map (\(k,v) -> "\n    " ++ k ++ ": " ++ v) entries) ++ "\n};\n"
                ++ "var page = Elm.fullscreen(Elm." ++ Module.nameToString elmModule ++ ", { " ++ portName ++ ": content });\n"


elm :: String -> [String] -> Snap ()
elm title elmModuleName =
  makeHtml title elmModuleName (return Nothing)


{'fraction_non_alphanumeric': 0.1275770070337133, 'fraction_numerical': 0.015765219500363813, 'mean_word_length': 2.652790079716563, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 20, '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': '2939712', 'n_tokens_mistral': 1350, 'n_tokens_neox': 1249, 'n_words': 343}