diff options
author | Ben Sima <ben@bsima.me> | 2020-03-31 11:39:49 -0700 |
---|---|---|
committer | Ben Sima <ben@bsima.me> | 2020-03-31 12:02:10 -0700 |
commit | 9f3804d5e4f28ea61a8abc856210422ad794b55e (patch) | |
tree | a2f12f2d227cec6bab827feef4ec2e49a5cbf5d0 /Run/Que/Website.hs | |
parent | 0b0972d31ab263c12d2cba621794bc6e7c3840bf (diff) |
Add Run.Que.Website server
This is a simple website server that uses que.run itself to host the que
webpages.
I had to rename Run.Que to Run.Que.Server because nix was
complaining about Run.Que being both a derivation and an attrset with
Run.Que.Website in it.
Diffstat (limited to 'Run/Que/Website.hs')
-rw-r--r-- | Run/Que/Website.hs | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/Run/Que/Website.hs b/Run/Que/Website.hs new file mode 100644 index 0000000..1de6bca --- /dev/null +++ b/Run/Que/Website.hs @@ -0,0 +1,45 @@ +-- | spawns a few processes that serve the que.run website +module Run.Que.Website where + +import Prelude +import System.Environment as Environment +import System.FilePath ( (</>) ) +import qualified System.Process as Process + +main :: IO () +main = do + args <- Environment.getArgs + let [src, ns] = if length args == 2 + then take 2 args + else if length args == 1 + then args ++ ["/"] + else error "usage: que-website <srcdir> [namespace]" + homepage <- getHomepageHtml (src </> "style.css") (src </> "index.md") + client <- readFile $ src </> "client.py" + putStrLn $ "serving " ++ src ++ " at " ++ ns + loop ns homepage client + +loop :: String -> FilePath -> FilePath -> IO () +loop ns homepage client = + serve (ns </> "index.html") homepage + >> serve (ns </> "_client/python") client + >> loop ns homepage client + +getHomepageHtml :: String -> String -> IO String +getHomepageHtml style index = Process.readProcess + "pandoc" + [ "--self-contained" + , "--css" + , style + , "-i" + , index + , "--from" + , "markdown" + , "--to" + , "html" + ] + [] + +serve :: FilePath -> FilePath -> IO () +serve path file = + Process.callProcess "curl" ["https://que.run" ++ path, "-d", file] |