1{-# LANGUAGE OverloadedStrings #-}
2import Control.Monad (filterM, when)
3import qualified Data.ByteString.Char8 as S8
4import Data.List (isInfixOf, isPrefixOf,
6import Network.HTTP.Client
7import Network.HTTP.Client.MultipartFormData
8import System.Directory (doesDirectoryExist,
10import System.Environment (getArgs, getEnv,
12import System.Exit (exitFailure)
13import System.Exit (ExitCode (ExitSuccess))
14import System.FilePath (takeDirectory, (</>))
15import System.Process (createProcess, cwd,
19main = withManager defaultManagerSettings $ \m -> do
21 token <- readFile "/auth-token"
24 [x, y] -> return (x, y)
30 , " <filepath> <alias name>"
34 let uploadDocs = "exclusive" `isInfixOf` alias
43 req1 <- parseUrl "http://www.stackage.org/upload"
45 [ partBS "alias" $ S8.pack alias
46 , partFileSource "stackage" filepath
48 req2 <- formDataBody formData req1
52 [ ("Authorization", S8.pack token)
53 , ("Accept", "application/json")
54 ] ++ requestHeaders req2
56 , checkStatus = \_ _ _ -> Nothing
61 case lookup "x-stackage-ident" $ responseHeaders res of
63 putStrLn $ "New ident: " ++ S8.unpack snapid
65 Nothing -> error $ "An error occurred: " ++ show res
68 putStrLn "Generating index file"
69 let root = takeDirectory filepath </> "haddock"
70 contents <- getDirectoryContents root
71 dirs <- filterM (\n -> doesDirectoryExist $ root </> n)
72 $ filter (not . ("." `isPrefixOf`))
74 writeFile (root </> "index.html") $ mkIndex (S8.unpack snapid) dirs
75 writeFile (root </> "style.css") styleCss
77 putStrLn "Creating tarball"
78 (Nothing, Nothing, Nothing, ph) <- createProcess
79 (proc "tar" $ "cJf" : "haddock.tar.xz" : "index.html" : "style.css" : dirs)
82 ec <- waitForProcess ph
84 then putStrLn "Haddock tarball generated"
85 else error "Error generating Haddock tarball"
87 putStrLn "Uploading Haddocks"
89 req1 <- parseUrl $ "http://www.stackage.org/upload-haddock/"
92 [ partFileSource "tarball" $ root </> "haddock.tar.xz"
94 req2 <- formDataBody formData req1
98 [ ("Authorization", S8.pack token)
99 , ("Accept", "application/json")
100 ] ++ requestHeaders req2
102 , checkStatus = \_ _ _ -> Nothing
104 httpLbs req3 m >>= print
106mkIndex :: String -> [String] -> String
107mkIndex snapid dirs = concat
108 [ "<!DOCTYPE html>\n<html lang='en'><head><title>Haddocks index</title>"
109 , "<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css'>"
110 , "<link rel='stylesheet' href='style.css'>"
111 , "<link rel='shortcut icon' href='http://www.stackage.org/static/img/favicon.ico' />"
113 , "<body><div class='container'>"
114 , "<div class='row'><div class='span12 col-md-12'>"
115 , "<h1>Haddock documentation index</h1>"
116 , "<p class='return'><a href=\"http://www.stackage.org/stackage/"
118 , "\">Return to snapshot</a></p><ul>"
119 , concatMap toLI dirs
120 , "</ul></div></div></div></body></html>"
133 [ "@media (min-width: 530px) {"
134 , "ul { -webkit-column-count: 2; -moz-column-count: 2; column-count: 2 }"
136 , "@media (min-width: 760px) {"
137 , "ul { -webkit-column-count: 3; -moz-column-count: 3; column-count: 3 }"
141 , " padding-left: 0;"
142 , " list-style-type: none;"
145 , " background: #f0f0f0;"
146 , " font-family: 'Lato', sans-serif;"
147 , " text-shadow: 1px 1px 1px #ffffff;"
148 , " font-size: 20px;"
149 , " line-height: 30px;"
150 , " padding-bottom: 5em;"
153 , " font-weight: normal;"
155 , " font-size: 45px;"
159 , " font-style: italic;"
162 , " margin-bottom: 1em;"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list