diff options
Diffstat (limited to 'services/tazblog/src/Blog.hs')
-rw-r--r-- | services/tazblog/src/Blog.hs | 62 |
1 files changed, 29 insertions, 33 deletions
diff --git a/services/tazblog/src/Blog.hs b/services/tazblog/src/Blog.hs index 6c61c2ce26c1..29fac37ac778 100644 --- a/services/tazblog/src/Blog.hs +++ b/services/tazblog/src/Blog.hs @@ -12,15 +12,22 @@ module Blog where import BlogStore -import Data.Text (Text, empty, pack) +import Data.Text (Text, pack) import qualified Data.Text as T import Data.Text.Lazy (fromStrict) import Data.Time -import Locales import Text.Blaze.Html (preEscapedToHtml) import Text.Hamlet import Text.Markdown +blogTitle :: Text = "tazjin's blog" + +repoURL :: Text = "https://bitbucket.org/tazjin/tazblog-haskell" + +mailTo :: Text = "mailto:mail@tazj.in" + +twitter :: Text = "https://twitter.com/tazjin" + replace :: Eq a => a -> a -> [a] -> [a] replace x y = map (\z -> if z == x then y else z) @@ -28,27 +35,25 @@ replace x y = map (\z -> if z == x then y else z) markdownCutoff :: Day markdownCutoff = fromGregorian 2013 04 28 -blogTemplate :: BlogLang -> Text -> Html -> Html -blogTemplate lang t_append body = +blogTemplate :: Text -> Html -> Html +blogTemplate t_append body = [shamlet| $doctype 5 <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> - <meta name="description" content=#{blogTitle lang t_append}> + <meta name="description" content=#{blogTitle}#{t_append}> <link rel="stylesheet" type="text/css" href="/static/blog.css" media="all"> - <link rel="alternate" type="application/rss+xml" title="RSS-Feed" href=#{rssUrl}> - <title>#{blogTitle lang t_append} + <link rel="alternate" type="application/rss+xml" title="RSS-Feed" href="/rss.xml"> + <title>#{blogTitle}#{t_append} <body> <header> <h1> - <a href="/" .unstyled-link>#{blogTitle lang empty} + <a href="/" .unstyled-link>#{blogTitle} <hr> ^{body} ^{showFooter} |] - where - rssUrl = T.concat ["/", show' lang, "/rss.xml"] showFooter :: Html showFooter = @@ -56,7 +61,7 @@ showFooter = <footer> <p .footer>Served without any dynamic languages. <p .footer> - <a href=#{repoURL} .uncoloured-link>Version #{version} + <a href=#{repoURL} .uncoloured-link> | <a href=#{twitter} .uncoloured-link>Twitter | @@ -90,28 +95,26 @@ $maybe links <- pageLinks ^{links} |] where - linkElems Entry {..} = concat $ ["/", show lang, "/", show entryId] + linkElems Entry {..} = concat $ ["/", show entryId] -showLinks :: Maybe Int -> BlogLang -> Html -showLinks (Just i) lang = +showLinks :: Maybe Int -> Html +showLinks (Just i) = [shamlet| $if ((>) i 1) <div .navigation> - <a href=#{nLink $ succ i} .uncoloured-link>#{backText lang} + <a href=#{nLink $ succ i} .uncoloured-link>Earlier | - <a href=#{nLink $ pred i} .uncoloured-link>#{nextText lang} + <a href=#{nLink $ pred i} .uncoloured-link>Later $elseif ((<=) i 1) - ^{showLinks Nothing lang} + ^{showLinks Nothing} |] where - nLink page = T.concat ["/", show' lang, "/?page=", show' page] -showLinks Nothing lang = + nLink page = T.concat ["/?page=", show' page] +showLinks Nothing = [shamlet| <div .navigation> - <a href=#{nLink} .uncoloured-link>#{backText lang} + <a href="/?page=2" .uncoloured-link>Earlier |] - where - nLink = T.concat ["/", show' lang, "/?page=2"] renderEntry :: Entry -> Html renderEntry e@Entry {..} = @@ -128,18 +131,11 @@ renderEntry e@Entry {..} = <hr> |] -showError :: BlogError -> BlogLang -> Html -showError NotFound l = - blogTemplate l (T.append ": " $ notFoundTitle l) - $ [shamlet| -<p>:( -<p>#{notFoundText l} -<hr> -|] -showError UnknownError l = - blogTemplate l "" +showError :: Text -> Text -> Html +showError title err = + blogTemplate (": " <> title) $ [shamlet| <p>:( -<p>#{unknownErrorText l} +<p>#{err} <hr> |] |