Functions for embedding a gitit wiki into a Happstack application.
The following is a minimal standalone wiki program:
import Network.Gitit
import Happstack.Server.SimpleHTTP
main = do
conf <- getDefaultConfig
createStaticIfMissing conf
createTemplateIfMissing conf
createRepoIfMissing conf
initializeGititState conf
simpleHTTP nullConf{port = 5001} $ wiki conf
Here is a more complex example, which serves different wikis
under different paths, and uses a custom authentication scheme:
import Network.Gitit
import Control.Monad
import Text.XHtml hiding (dir)
import Happstack.Server.SimpleHTTP
import My.Auth.System (myGetUser, myLoginUser, myLogoutUser)
type WikiSpec = (String, FileStoreType, PageType)
wikis = [ ("markdownWiki", Git, Markdown)
, ("latexWiki", Darcs, LaTeX) ]
-- custom authentication
withUser :: Handler -> Handler
withUser handler = do
user <- myGetUser
localRq (setHeader "REMOTE_USER" user) handler
myAuthHandler = msum
[ dir "_login" myLoginUser
, dir "_logout" myLogoutUser ]
handlerFor :: Config -> WikiSpec -> ServerPart Response
handlerFor conf (path', fstype, pagetype) = dir path' $
wiki conf{ repositoryPath = path'
, repositoryType = fstype
, defaultPageType = pagetype}
indexPage :: ServerPart Response
indexPage = ok $ toResponse $
(p << "Wiki index") +++
ulist << map (\(path', _, _) -> li << hotlink (path' ++ "/") << path') wikis
main = do
conf <- getDefaultConfig
let conf' = conf{authHandler = myAuthHandler}
forM wikis $ \(path', fstype, pagetype) -> do
let conf'' = conf'{ repositoryPath = path'
, repositoryType = fstype
, defaultPageType = pagetype
}
createStaticIfMissing conf''
createRepoIfMissing conf''
createTemplateIfMissing conf'
initializeGititState conf'
simpleHTTP nullConf{port = 5001} $
(nullDir >> indexPage) `mplus` msum (map (handlerFor conf') wikis)
|