diff options
author | Ben Sima <ben@bsima.me> | 2020-04-15 10:06:24 -0700 |
---|---|---|
committer | Ben Sima <ben@bsima.me> | 2020-04-15 10:07:02 -0700 |
commit | afa9d701538b9e56622a0bfdf8e04aa358c9cd82 (patch) | |
tree | dee95c3955b3fe3d11e80d89823660d28eee0587 /Que/Website.hs | |
parent | f4b8c0df041b063c0b47d2ec6c818a9c202fd833 (diff) |
Reformatting
Now I'm using ormolu instead of brittany for Haskell formatting
now. Figured I should just make all of these big changes at once.
Diffstat (limited to 'Que/Website.hs')
-rw-r--r-- | Que/Website.hs | 147 |
1 files changed, 78 insertions, 69 deletions
diff --git a/Que/Website.hs b/Que/Website.hs index e75f2bd..cfb860c 100644 --- a/Que/Website.hs +++ b/Que/Website.hs @@ -1,7 +1,7 @@ -{-# LANGUAGE RecordWildCards #-} +{-# LANGUAGE LambdaCase #-} {-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE RecordWildCards #-} {-# LANGUAGE NoImplicitPrelude #-} -{-# LANGUAGE LambdaCase #-} -- | spawns a few processes that serve the que.run website -- @@ -13,39 +13,41 @@ -- : dep protolude -- : dep req module Que.Website - ( main + ( main, ) where -import Alpha -import qualified Control.Concurrent.Async as Async -import qualified Data.ByteString.Char8 as BS -import qualified Data.Ini.Config as Config -import qualified Data.Text as Text -import Data.Text.Encoding ( encodeUtf8 ) -import qualified Data.Text.IO as Text -import Network.HTTP.Req -import qualified System.Directory as Directory -import System.Environment as Environment -import qualified System.Exit as Exit -import System.FilePath ( (</>) ) -import qualified System.Process as Process +import Alpha +import qualified Control.Concurrent.Async as Async +import qualified Data.ByteString.Char8 as BS +import qualified Data.Ini.Config as Config +import qualified Data.Text as Text +import Data.Text.Encoding (encodeUtf8) +import qualified Data.Text.IO as Text +import Network.HTTP.Req +import qualified System.Directory as Directory +import System.Environment as Environment +import qualified System.Exit as Exit +import System.FilePath ((</>)) +import qualified System.Process as Process main :: IO () main = do (src, ns) <- Environment.getArgs >>= \case - [src] -> return (src, "_") -- default to _ ns which is special + [src] -> return (src, "_") -- default to _ ns which is special [src, ns] -> return (src, Text.pack ns) - _ -> Exit.die "usage: que-website <srcdir> [namespace]" + _ -> Exit.die "usage: que-website <srcdir> [namespace]" mKey <- getKey ns putText $ "serving " <> Text.pack src <> " at " <> ns - run mKey ns $ Sources { index = src </> "index.md" - , client = src </> "client.py" - , quescripts = src </> "quescripts.md" - , style = src </> "style.css" - , apidocs = src </> "apidocs.md" - , tutorial = src </> "tutorial.md" - } + run mKey ns $ + Sources + { index = src </> "index.md", + client = src </> "client.py", + quescripts = src </> "quescripts.md", + style = src </> "style.css", + apidocs = src </> "apidocs.md", + tutorial = src </> "tutorial.md" + } getKey :: Namespace -> IO (Maybe Key) getKey ns = do @@ -63,64 +65,71 @@ getKey ns = do errorParsingConf :: error errorParsingConf = panic "could not parse ~/.config/que.conf" -data Sources = Sources - { index :: FilePath - , quescripts :: FilePath - , client :: FilePath - , style :: FilePath - , tutorial :: FilePath - , apidocs :: FilePath - } +data Sources + = Sources + { index :: FilePath, + quescripts :: FilePath, + client :: FilePath, + style :: FilePath, + tutorial :: FilePath, + apidocs :: FilePath + } type Namespace = Text + type Key = Text auth :: Namespace -> Config.IniParser (Maybe Key) auth "pub" = pure Nothing -auth ns = Config.sectionMb ns <| Config.field "key" +auth ns = Config.sectionMb ns <| Config.field "key" run :: Maybe Key -> Text -> Sources -> IO () run key ns Sources {..} = Async.runConcurrently actions >> return () - where - actions = traverse - Async.Concurrently - [ forever <| toHtml index >>= serve key ns "index" - , forever <| toHtml quescripts >>= serve key ns "quescripts" - , forever <| BS.readFile client >>= serve key ns "client" - , forever <| toHtml tutorial >>= serve key ns "tutorial" - , forever <| toHtml apidocs >>= serve key ns "apidocs" - ] - toHtml :: FilePath -> IO ByteString - toHtml md = - BS.pack - <$> Process.readProcess - "pandoc" - [ "--include-in-header" - , style - , "-i" - , md - , "--from" - , "markdown" - , "--to" - , "html" - ] - [] + where + actions = + traverse + Async.Concurrently + [ forever <| toHtml index >>= serve key ns "index", + forever <| toHtml quescripts >>= serve key ns "quescripts", + forever <| BS.readFile client >>= serve key ns "client", + forever <| toHtml tutorial >>= serve key ns "tutorial", + forever <| toHtml apidocs >>= serve key ns "apidocs" + ] + toHtml :: FilePath -> IO ByteString + toHtml md = + BS.pack + <$> Process.readProcess + "pandoc" + [ "--include-in-header", + style, + "-i", + md, + "--from", + "markdown", + "--to", + "html" + ] + [] serve :: Maybe Key -> Namespace -> Text -> ByteString -> IO () serve Nothing "pub" path content = runReq defaultHttpConfig $ do - _ <- req POST - (http "que.run" /: "pub" /: path) - (ReqBodyBs content) - ignoreResponse - mempty + _ <- + req + POST + (http "que.run" /: "pub" /: path) + (ReqBodyBs content) + ignoreResponse + mempty liftIO $ return () -serve Nothing p _ _ = panic <| "no auth key provided for ns: " <> p +serve Nothing p _ _ = panic <| "no auth key provided for ns: " <> p serve (Just key) ns path content = runReq defaultHttpConfig $ do let options = header "Authorization" (encodeUtf8 key) <> responseTimeout maxBound - _ <- req POST - (http "que.run" /: ns /: path) - (ReqBodyBs content) - ignoreResponse - options + _ <- + req + POST + (http "que.run" /: ns /: path) + (ReqBodyBs content) + ignoreResponse + options liftIO $ return () |