blogination 0.2 → 0.3
raw patch · 3 files changed
+35/−6 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Text.Blogination: blogAnalytics :: Blog -> Maybe String
- Text.Blogination: Blog :: String -> String -> [String] -> FilePath -> FilePath -> String -> Bool -> String -> FilePath -> String -> Blog
+ Text.Blogination: Blog :: String -> String -> [String] -> FilePath -> FilePath -> String -> Bool -> String -> FilePath -> String -> Maybe String -> Blog
Files
- blogination.cabal +1/−1
- executable/Main.hs +9/−2
- library/Text/Blogination.hs +25/−3
blogination.cabal view
@@ -1,5 +1,5 @@ name: blogination-version: 0.2+version: 0.3 synopsis: Very simple static blog software description: Blogination reads files written in markdown and outputs xhtml. Supports syntax highlighting. Philosophy is simplicity. Can be used as a library, in a web application for example. Intended use is a simple commandline program to run after changes are made. Ideally use darcs or git with it. category: Web
executable/Main.hs view
@@ -21,15 +21,22 @@ instance Monad m => Applicative (ErrorT C.CPError m) where pure = return; (<*>) = ap +instance Monad m => Alternative (ErrorT C.CPError m) where+ empty = mzero; (<|>) = mplus+ getConf :: FilePath -> IO (Either (C.CPErrorData,String) Blog) getConf filePath = runErrorT $ do contents <- liftIO $ readFile filePath config <- C.readstring C.emptyCP contents let get = C.get config "BLOG"- Blog <$> get "name" <*> get "root"- <*> (read <$> get "css") <*> get "entries" <*> get "html"+ Blog <$> get "name" + <*> get "root"+ <*> (read <$> get "css") + <*> get "entries" + <*> get "html" <*> get "author" <*> return False <*> get "date" <*> return "tags" <*> get "url"+ <*> (Just <$> get "analytics" <|> return Nothing)
library/Text/Blogination.hs view
@@ -46,6 +46,7 @@ -- "%A %d %b, %Y" makes "Tuesday 10 Feb, 2009" , blogTags :: FilePath , blogURL :: String -- e.g. "http://chrisdone.com/blog"+ , blogAnalytics :: Maybe String -- google analytics ID e.g. UA-7443395-1 } deriving (Read,Show) type Blogination = ErrorT String (StateT Blog IO)@@ -106,12 +107,13 @@ renderTagHtml tag = do blog@Blog{..} <- lift get links <- mapM getEntryLink =<< getTagEntryNames tag+ anal <- analytics let html = [head,thebody] head = header << [toHtml $ map style blogCSS ,encoding ,thetitle << title ,rss]- thebody = body << [back,hr,name,menu,hr,back]+ thebody = body << [back,hr,name,menu,hr,back,anal] title = tag ++ " - " ++ blogName name = h2 << ("Tag: " ++ tag) menu = ulist << map ((li<<) . showLink) links@@ -134,8 +136,9 @@ blog@Blog{..} <- lift get links <- mapM getEntryLink =<< getEntryNames alltags <- getTags+ anal <- analytics let html = toHtml [header<<[title,encoding,rss]- ,body<<[name,menu,tags]]+ ,body<<[name,menu,tags,anal]] title = thetitle << blogName name = h1 << blogName menu = h2 << "Posts" +++ ul (map showLink links)@@ -232,7 +235,8 @@ head = header << [toHtml $ map style blogCSS ,encoding ,thetitle << title]- thebody = body << [back,hr,tagndate,html,hr,back]+ thebody = body << [back,hr,tagndate,html,hr,back,anal]+ anal = analyticsScript blogAnalytics back = toHtml $ p << hotlink blogRoot << ("« Back to " ++ blogName) style css = thelink ! [rel "stylesheet",href (blogRoot++css)] << noHtml@@ -241,6 +245,24 @@ tag = "Tags: " +++ (mconcat $ intersperse (toHtml ", ") taglinks) taglinks = map (mkTagLink blog) tags showTime = toHtml . formatTime defaultTimeLocale blogDate++analytics :: Blogination Html+analytics = do+ Blog{..} <- lift get+ return $ analyticsScript blogAnalytics++analyticsScript :: Maybe String -> Html+analyticsScript = maybe noHtml script where+ script blogAnalytics = primHtml $+ "<script type=\"text/javascript\">\+ \var gaJsHost = ((\"https:\" == document.location.protocol) ? \+ \ \"https://ssl.\" : \"http://www.\"); \+ \ document.write(unescape(\"%3Cscript src='\" + gaJsHost + \+ \ \"google-analytics.com/ga.js' \+ \ type='text/javascript'%3E%3C/script%3E\")); </script> \+ \ <script type=\"text/javascript\"> try { \+ \ var pageTracker = _gat._getTracker(\"" ++ blogAnalytics ++ "\"); \+ \ pageTracker._trackPageview(); } catch(err) {}</script>" mkTagLink :: Blog -> FilePath -> Html mkTagLink Blog{..} tag =