blob: 1de6bca362324676670df9709c6f25911b9d5a2b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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]
|