module Hakyll.Web.Meta.TwitterCard
( twitterCardField
) where
import Hakyll.Core.Compiler
import Hakyll.Core.Item
import Hakyll.Web.Template
import Hakyll.Web.Template.Context
twitterCardField :: String -> Context String -> Context String
String
k Context String
ctx = String
-> ([String] -> Item String -> Compiler String) -> Context String
forall a.
String -> ([String] -> Item a -> Compiler String) -> Context a
functionField String
k (([String] -> Item String -> Compiler String) -> Context String)
-> ([String] -> Item String -> Compiler String) -> Context String
forall a b. (a -> b) -> a -> b
$ \[String]
_args Item String
i -> do
Template
template <- Compiler Template
twitterCardTemplate
Item String -> String
forall a. Item a -> a
itemBody (Item String -> String)
-> Compiler (Item String) -> Compiler String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Template -> Context String -> Item String -> Compiler (Item String)
forall a. Template -> Context a -> Item a -> Compiler (Item String)
applyTemplate Template
template Context String
ctx Item String
i
twitterCardTemplate :: Compiler Template
= do
String -> Compiler (Item String)
forall a. a -> Compiler (Item a)
makeItem String
twitterCardTemplateString Compiler (Item String)
-> (Item String -> Compiler Template) -> Compiler Template
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Item String -> Compiler Template
compileTemplateItem
twitterCardTemplateString :: String
=
String
"<meta name=\"twitter:card\" content=\"summary\" />\
\$if(twitter-creator)$<meta property=\"twitter:creator\" content=\"$twitter-creator$\" />$endif$\
\$if(twitter-site)$<meta property=\"twitter:site\" content=\"$twitter-site$\" />$endif$"