From 964cfe55edf5a5d613830f10b2741a29afe0becb Mon Sep 17 00:00:00 2001 From: nek0 Date: Tue, 10 May 2016 00:40:27 +0200 Subject: [PATCH] urlencode stuff --- nek0-blog.cabal | 1 + src/Main.hs | 16 +++++++++++----- templates/post.html | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/nek0-blog.cabal b/nek0-blog.cabal index 7d7b8ee..33458db 100644 --- a/nek0-blog.cabal +++ b/nek0-blog.cabal @@ -26,3 +26,4 @@ executable blog build-depends: base , hakyll , directory + , HTTP diff --git a/src/Main.hs b/src/Main.hs index 3583c62..471f026 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -5,6 +5,7 @@ import Hakyll import Data.Monoid ((<>), mconcat) import Data.List (sort, delete, intercalate) import System.Directory +import Network.HTTP.Base (urlEncode) -------------------------------------------------------------------------------- main :: IO () @@ -65,12 +66,15 @@ main = do paginateRules pages $ \num _ -> do route $ setExtension "html" compile $ do - let ident = paginateMakeId pages $ num + ident <- getUnderlying tagList <- getTags ident let tagString = intercalate "," tagList + meta <- getMetadata ident + title <- getMetadataField' ident "title" + let url = toFilePath ident compiled <- getResourceBody >>= renderPandoc let pageCtx = paginateContext pages num - let ctx = (postCtx tags) <> pageCtx <> flattrCtx tagString + let ctx = (postCtx tags) <> pageCtx <> flattrCtx tagString (urlEncode title) (urlEncode $ "htps://nek0.eu" ++ url) full <- loadAndApplyTemplate "templates/post.html" ctx compiled _ <- saveSnapshot "content" compiled loadAndApplyTemplate "templates/default.html" baseCtx full @@ -142,9 +146,11 @@ feedCtx = mconcat -------------------------------------------------------------------------------- -flattrCtx :: String -> Context String -flattrCtx str = mconcat - [ constField "rawtags" str +flattrCtx :: String -> String -> String -> Context String +flattrCtx tag tit url = mconcat + [ constField "rawtags" tag + , constField "enctitle" tit + , constField "encurl" url ] -------------------------------------------------------------------------------- diff --git a/templates/post.html b/templates/post.html index 6d2d75c..10a7494 100644 --- a/templates/post.html +++ b/templates/post.html @@ -10,7 +10,7 @@ $body$ -flattr this! +flattr this!