Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 41 lines (36 sloc) 1.301 kb
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
{-# LANGUAGE TemplateHaskell, QuasiQuotes, OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
module Handler.Root
    ( getRootR
    , getPageR
    , getStaticContentR
    ) where

import Wiki
import Handler.Topic (getTopicR')
import Text.Hamlet (hamlet)
import Util (renderContent)

getRootR :: Handler RepHtml
getRootR = do
    mpage <- runDB $ getBy $ UniquePage ""
    mcontent <-
        case mpage of
            Nothing -> return Nothing
            Just (_, Page { pageTopic = tid }) -> runDB $ do
                x <- selectList [TopicContentTopic ==. tid] [Desc TopicContentChanged, LimitTo 1]
                case x of
                    [] -> return Nothing
                    (_, TopicContent {..}):_ -> return $ Just (topicContentFormat, topicContentContent, tid)
    let html' =
            case mcontent of
                Nothing -> [hamlet|
<h1>No homepage set.
<p>The site admin has no yet set a homepage topic.
|]
                Just (format, content, tid) -> renderContent tid format content
    defaultLayout $ addHamlet html'

getPageR :: Text -> Handler RepHtml
getPageR t = do
    p <- runDB $ getBy404 (UniquePage t)
    getTopicR' (return ()) False $ pageTopic $ snd p

getStaticContentR :: StaticContentId -> Handler StaticContent
getStaticContentR = runDB . get404
Something went wrong with that request. Please try again.