module Hope.Module.Front (module_front) where import Hope.Module import Hope.Setting.Types import Hope.View -- FIXME: needed by the crazy menu item hack import Hope.Module.Static.Operations import Hope.Module.Static.Types import Hope.Util.XHtml import Control.Monad module_front :: Module module_front = emptyModule { moduleName = "front", moduleResources = frontResources, moduleNav = frontNav, moduleSettings = settings } -- * Settings settings :: [SettingDesc] settings = [settingDesc frontPath, settingDesc frontMenuPages] defaultFrontPage :: Path defaultFrontPage = ["entry"] frontPath :: Setting Path frontPath = setting "front" "path" defaultFrontPage "Front page path" -- * Navigation frontNav :: Hope (Maybe (Tree Html)) frontNav = do ls <- getSetting frontMenuPages >>= mapM pageLink fp <- getSetting frontPath frontIsStatic <- getSetting frontPath >>= isStaticPage return $ if not frontIsStatic && null ls then Nothing else Just $ Node (reslink [] << "Home") (map (flip Node []) ls) frontMenuPages :: Setting [Path] frontMenuPages = setting "front" "menuPages" [] "Menu pages" -- * Resources frontResources :: ResourceHandler frontResources = resources $ \p -> case p of [] -> do p <- getSetting frontPath case p of -- the empty path is set as the front page, let someone else -- (i.e. the static module) handle it. [] -> return [] _ -> return $ [get (redirectRes p)] _ -> return [] -- * HTML generation -- FIXME: HACK!!!!1!, only works well for static pages pageLink :: Path -> Hope Html pageLink p = do mst <- getStaticByPath p return $ case mst of Nothing -> reslink p << showPath p Just st -> staticPageLink st staticPageLink :: Static -> Html staticPageLink s = reslink (staticPath s) << staticTitle s