about summary refs log tree commit diff
path: root/src/Blog.hs
diff options
context:
space:
mode:
author"Vincent Ambo ext:(%22) <tazjin@gmail.com>2013-04-28T12·26+0200
committer"Vincent Ambo ext:(%22) <tazjin@gmail.com>2013-04-28T12·26+0200
commit8f1b6b5c4e34c59d7ceb19ef2fe552a104d7bf62 (patch)
treefac53f72105e1ee0de86929c4fed72214b33b35b /src/Blog.hs
parent0f98c3f489b8a00f1a6ce539b8f853a07610c2e1 (diff)
* added Markdown support
Diffstat (limited to 'src/Blog.hs')
-rw-r--r--src/Blog.hs35
1 files changed, 29 insertions, 6 deletions
diff --git a/src/Blog.hs b/src/Blog.hs
index d3382357fc2b..9c66a20101c8 100644
--- a/src/Blog.hs
+++ b/src/Blog.hs
@@ -5,14 +5,17 @@ module Blog where
 import Control.Monad (when, unless)
 import Data.Data (Data, Typeable)
 import Data.List (intersperse)
+import Data.Maybe (fromJust)
 import Data.Monoid (mempty)
 import Data.Text (Text, append, pack, empty)
+import Data.Text.Lazy (fromStrict)
 import Data.Time
 import Network.Captcha.ReCaptcha
 import System.Locale (defaultTimeLocale)
 import Text.Blaze.Html (preEscapedToHtml)
 import Text.Hamlet
-import Text.Lucius 
+import Text.Lucius
+import Text.Markdown
 import Locales
 import BlogDB
 
@@ -28,11 +31,16 @@ replace x y = map (\z -> if z == x then y else z)
 show' :: Show a => a -> Text
 show' = pack . show
 
+-- |After this time all entries are Markdown
+markdownCutoff :: UTCTime
+markdownCutoff = fromJust $ parseTime defaultTimeLocale "%s" "1367149834"
+
 data BlogURL = BlogURL
 
 -- blog CSS (admin is still static)
 stylesheetSource = $(luciusFile "res/blogstyle.lucius")
 blogStyle = renderCssUrl undefined stylesheetSource 
+
 -- blog HTML
 blogTemplate :: BlogLang -> Text -> Html -> Html
 blogTemplate lang t_append body = [shamlet|
@@ -78,6 +86,12 @@ showFooter l v = [shamlet|
   <a class="link" href="/notice">#{noticeText l}
 |]
 
+isEntryMarkdown :: Entry -> Bool
+isEntryMarkdown e = edate e > markdownCutoff
+
+renderEntryMarkdown :: Text -> Html
+renderEntryMarkdown = markdown def {msXssProtect = False} . fromStrict
+
 renderEntries :: Bool -> [Entry] -> Text -> Maybe Html -> Html
 renderEntries showAll entries topText footerLinks = [shamlet|
 <span class="innerTitle">#{topText}
@@ -85,8 +99,13 @@ renderEntries showAll entries topText footerLinks = [shamlet|
  <ul style="max-width:57em;">
   $forall entry <- elist
    <li>
-    <a href=#{linkElems entry}>#{linkText $ length $ comments entry}
-    ^{preEscapedToHtml $ append " " $ btext entry}
+    $if (isEntryMarkdown entry)
+      <a href=#{linkElems entry}>#{linkText $ length $ comments entry}
+      <b>#{title entry}
+      ^{renderEntryMarkdown $ append " " $ btext entry}
+    $else
+      <a href=#{linkElems entry}>#{linkText $ length $ comments entry}
+      ^{preEscapedToHtml $ append " " $ btext entry}
     $if ((/=) (mtext entry) empty)
      <p><a href=#{linkElems entry}>#{readMore $ lang entry}
     $else
@@ -119,7 +138,7 @@ showLinks Nothing lang = [shamlet|
    nLink = T.concat ["/", show' lang, "/?page=2"]
 
 renderEntry :: Entry -> Html
-renderEntry Entry{..} = [shamlet|
+renderEntry e@Entry{..} = [shamlet|
 <span class="innerTitle">#{title}
 <span class="righttext">
  <i>#{woText}
@@ -127,8 +146,12 @@ renderEntry Entry{..} = [shamlet|
  <article>
   <ul style="max-width:57em;">
    <li>
-    ^{preEscapedToHtml $ btext}
-    <p>^{preEscapedToHtml $ mtext}
+    $if (isEntryMarkdown e)
+      ^{renderEntryMarkdown btext}
+      <p>^{renderEntryMarkdown $ mtext}
+    $else
+      ^{preEscapedToHtml $ btext}
+      <p>^{preEscapedToHtml $ mtext}
  <div class="innerBoxComments">
   <div class="cHead">#{cHead lang}
   <ul style="max-width:57em;">#{renderComments comments lang}