From 46c1b6e97fa59ad3ed43a43df07638c898f352ee Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Mon, 15 Dec 2014 18:13:48 +0200 Subject: [PATCH] Initial older releases code --- Data/WebsiteContent.hs | 19 ++++++++++++------- Handler/Home.hs | 3 +++ config/routes | 1 + 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Data/WebsiteContent.hs b/Data/WebsiteContent.hs index 4d03d60..2dc7cef 100644 --- a/Data/WebsiteContent.hs +++ b/Data/WebsiteContent.hs @@ -10,17 +10,22 @@ data WebsiteContent = WebsiteContent { wcHomepage :: !Html , wcAuthors :: !Html , wcInstall :: !Html + , wcOlderReleases :: !Html } loadWebsiteContent :: FilePath -> IO WebsiteContent loadWebsiteContent dir = do - wcHomepage <- fmap (preEscapedToMarkup :: Text -> Html) - $ readFile $ dir "homepage.html" - wcAuthors <- fmap (preEscapedToMarkup :: Text -> Html) - $ readFile $ dir "authors.html" - wcInstall <- fmap (markdown def + wcHomepage <- readHtml "homepage.html" + wcAuthors <- readHtml "authors.html" + wcInstall <- readMarkdown "install.md" + wcOlderReleases <- readHtml "older-releases.html" `catchIO` + \_ -> readMarkdown "older-releases.md" + return WebsiteContent {..} + where + readHtml fp = fmap (preEscapedToMarkup :: Text -> Html) + $ readFile $ dir fp + readMarkdown fp = fmap (markdown def { msXssProtect = False , msAddHeadingId = True }) - $ readFile $ dir "install.md" - return WebsiteContent {..} + $ readFile $ dir fp diff --git a/Handler/Home.hs b/Handler/Home.hs index 97a5873..3a68c5d 100644 --- a/Handler/Home.hs +++ b/Handler/Home.hs @@ -22,6 +22,9 @@ getAuthorsR = contentHelper "Library Authors" wcAuthors getInstallR :: Handler Html getInstallR = contentHelper "Haskell Installation Instructions" wcInstall +getOlderReleasesR :: Handler Html +getOlderReleasesR = contentHelper "Older Releases" wcOlderReleases + contentHelper :: Html -> (WebsiteContent -> Html) -> Handler Html contentHelper title accessor = do homepage <- getYesod >>= fmap accessor . liftIO . grContent . websiteContent diff --git a/config/routes b/config/routes index cd27a81..4fdb0d3 100644 --- a/config/routes +++ b/config/routes @@ -49,3 +49,4 @@ /authors AuthorsR GET /install InstallR GET +/older-releases OlderReleasesR GET