panda 0.0.0.3 → 0.0.0.4
raw patch · 19 files changed
+86/−83 lines, 19 filesdep +utf8-stringdep ~pandoc
Dependencies added: utf8-string
Dependency ranges changed: pandoc
Files
- Panda/Config/Global.hs +8/−4
- Panda/Controller/Application.hs +10/−9
- Panda/Helper/Env.hs +3/−3
- Panda/Helper/Helper.hs +11/−24
- Panda/Model/Post.hs +2/−2
- Panda/Model/Tag.hs +7/−7
- Panda/Type/State.hs +1/−3
- Panda/View/RSS.hs +7/−3
- Panda/View/Theme/BluePrint/Helper.hs +1/−1
- Panda/View/Theme/BluePrint/Post.hs +2/−2
- Panda/View/Theme/BluePrint/Search.hs +1/−1
- Panda/View/Theme/BluePrint/Static.hs +2/−2
- Panda/View/Theme/BluePrint/Tag.hs +1/−1
- Panda/View/Theme/BluePrint/Template/Body.hs +8/−13
- Panda/View/Theme/BluePrint/Template/Footer.hs +2/−2
- Panda/View/Theme/BluePrint/Template/Header.hs +1/−1
- Panda/View/Theme/BluePrint/Template/Sidebar.hs +3/−3
- changelog.markdown +14/−0
- panda.cabal +2/−2
Panda/Config/Global.hs view
@@ -2,6 +2,7 @@ import Panda.Helper.Env import Prelude hiding ((.), (/), id)+import System.IO.UTF8 as UIO db_id = "db" flat_id = "."@@ -22,14 +23,17 @@ -- unsafe, must restart server after changing config file, sorry about that ... -- but these configs are read only, and keep the view pure, so no monad headaches involved. -user_config = readFile config_uri .purify .split' .map strip .map (split "\\s*=\\s*") .map tuple2-config_for s = user_config.lookup s.fromJust .fromUTF8+user_config = UIO.readFile config_uri .purify .filter_comment .lines .map strip .map (split "\\s*=\\s*") .map tuple2+config_for' s d = user_config.lookup s .fromMaybe d +config_for s = config_for' s s+ blog_title = config_for "blog_title" blog_subtitle = config_for "blog_subtitle" host_name = config_for "host_name"-author_email = config_for "author_email"+author_email = config_for "author_email" panda_url = "http://github.com/nfjinjing/panda" -per_page = 7 :: Int+per_page = config_for' "per_page" "7" .read :: Int+navigation = config_for' "navigation" "About" .split "," .map strip .reject null .("Home" :)
Panda/Controller/Application.hs view
@@ -44,14 +44,14 @@ blogs <- Post.list.liftIO p <- pager per_page $ blogs.length tags <- Tag.list.liftIO- let nav = if p.Pager.current == 1 then Home else Other+ let nav = if p.Pager.current == 1 then home_nav else no_navigation let state = State Config.blog_id p tags nav blogs.map (Tag.fill_tag tags) .PostV.list state .output_html index_feed = do blogs <- Post.list.liftIO- blogs.RSSV.rss.output+ blogs.RSSV.rss "" "" .output blog = do@@ -59,38 +59,39 @@ blog <- Post.get id .liftIO tags <- Tag.list.liftIO - let state = State id Pager.empty tags Other+ let state = State id Pager.empty tags no_navigation blog.Tag.fill_tag tags .PostV.view state .output_html static = do id <- uri tags <- Tag.list.liftIO - let nav = if id.split "/" .tail.join "/" == "about" then About else Other+ let nav = if r.belongs_to Config.navigation then r else no_navigation where r = id.id_to_resource let state = State id Pager.empty tags nav (Config.flat_uri / id) .readFile .liftIO <.> StaticV.view state >>= output_html + tag = do id <- uri tags <- Tag.list.liftIO- let tag_name = Tag.id_to_name id+ let tag_name = Tag.get_name id case Tag.tag_map' tags .Map.lookup tag_name of Nothing -> "page not found" .output Just blog_set -> do blogs <- blog_set.to_list.rsort.mapM (Post.get) .liftIO <.> map (Tag.fill_tag tags) p <- pager per_page $ blogs.length- let state = State id p tags Other+ let state = State id p tags no_navigation blogs.TagV.view state.output_html tag_feed = do id <- uri <.> (split "/" >>> init >>> join "/") tags <- Tag.list.liftIO- let tag_name = Tag.id_to_name id+ let tag_name = Tag.get_name id case Tag.tag_map' tags .Map.lookup tag_name of Nothing -> "page not found" .output Just blog_set -> do blogs <- blog_set.to_list.rsort.mapM (Post.get) .liftIO <.> map (Tag.fill_tag tags)- blogs.RSSV.rss.output+ blogs.RSSV.rss "tag" tag_name.output search = do s <- param_with_default "s" ""@@ -99,6 +100,6 @@ p <- pager per_page $ blogs.length tags <- Tag.list.liftIO query <- uri- let state = State query p tags Other+ let state = State query p tags no_navigation blogs.map (Tag.fill_tag tags) .SearchV.view state s.output_html
Panda/Helper/Env.hs view
@@ -4,8 +4,7 @@ , module Control.Arrow , module Data.List , module Network.URI - , module Network.CGI - , module Text.Pandoc.UTF8 + , module Network.CGI , module System.Locale , module System.Time.Parse , module Panda.Helper.Helper@@ -18,8 +17,9 @@ import Data.List import Network.URI import Network.CGI-import Text.Pandoc.UTF8 import System.Locale import System.Time.Parse import Panda.Helper.Helper import Data.Maybe++
Panda/Helper/Helper.hs view
@@ -16,7 +16,6 @@ import Panda.Helper.Escape import Char import Data.List-import System.Directory (/) = (</>) @@ -31,17 +30,9 @@ '?':s -> s.formDecode .return otherwise -> return [] -param_with_default s d = do- ps <- params- return $ case ps.lookup s of- Nothing -> d- Just x -> x.unescape.strip+param_with_default s d = params <.> (lookup s >>> fromMaybe d >>> unescape >>> strip) -input_with_default s d = do- input <- getInput s- return $ case input of- Nothing -> d- Just x -> x.unescape.strip+input_with_default s d = getInput s <.> (fromMaybe d >>> unescape >>> strip) pager length total = liftM5 ( Pager length ) current has_next has_previous next previous where current = param_with_default "page" "1" <.> read@@ -53,6 +44,11 @@ for_current_page p xs = xs.drop ((p.Pager.current - 1) * p.Pager.length) .take (p.Pager.length) +-- id: /type/resoruce+id_to_type id = id.split "/" .first+id_to_resource id = id.split "/" .tail.join "/"+no_navigation = ""+home_nav = "Home" -- view id = identifier@@ -77,19 +73,10 @@ ] .join' .primHtml rss_uri x = URI {- uriScheme = "http://",+ uriScheme = "http://", uriAuthority = Nothing,- uriPath = x / "rss.xml",- uriQuery = "",- uriFragment = ""+ uriPath = x / "rss.xml",+ uriQuery = "",+ uriFragment = "" } ----- generic-lower = map toLower-upper = map toUpper--ls s = getDirectoryContents s <.> (\\ [".", ".."])--filter_comment = lines >>> map strip >>> reject null >>> reject (head >>> (== '#')) >>> join "\n"
Panda/Model/Post.hs view
@@ -18,11 +18,11 @@ list = ls Config.blog_uri <.> rsort <.> map (Config.blog_id /) >>= mapM get get id = liftM2 (Post id (get_title id) ) (get_body id) (return [])-get_title id = id.fromUTF8.words.tail.join " "+get_title id = id.from_utf8.words.tail.join " " get_body id = (Config.flat_uri / id) .readFile parse_date = parseCalendarTime defaultTimeLocale "%Y-%m-%d"-date x = case x.uid.fromUTF8.words.first.split "/".last.("20"++).parse_date of+date x = case x.uid.words.first.split "/".last.("20"++).parse_date of Nothing -> parse_date "2000-1-1".fromJust Just x -> x
Panda/Model/Tag.hs view
@@ -10,25 +10,25 @@ import qualified Data.Set as Set import qualified Data.Map as Map import qualified Data.List as List-import Panda.Config.Global as Config+import qualified Panda.Config.Global as Config data Tag = Tag { uid :: String -- tag/name+ , name :: String , resources :: Set.Set String } deriving (Show, Eq) -name x = x.uid.id_to_name-id_to_name x = x.split "/" .tail.join'-sorted xs = xs.List.sortBy(\a b -> (b.resources.Set.size) `compare` (a.resources.Set.size))-name_to_id x = tag_id / x+sorted xs = xs.List.sortBy(compare_by (resources >>> Set.size)).reverse+name_to_id x = Config.tag_id / (x.to_utf8) list = ls Config.tag_uri <.> map (Config.tag_id /) >>= mapM get -get id = get_resources id <.> Tag id+get id = get_resources id <.> Tag id (get_name id)+get_name id = id.from_utf8.split "/" .tail.join' get_resources id = (Config.flat_uri / id) .readFile - <.> filter_comment <.> lines <.> map (blog_id / ) <.> to_set+ <.> filter_comment <.> lines <.> map (Config.blog_id / ) <.> to_set to_tuple x = (x.name, x.resources)
Panda/Type/State.hs view
@@ -10,7 +10,5 @@ -- theme state , tags :: [Tag]- , nav_location :: NavLocation+ , nav_location :: String }- -data NavLocation = Home | About | Other deriving (Eq, Show)
Panda/View/RSS.hs view
@@ -3,7 +3,7 @@ -- env import Panda.Helper.Env import Prelude hiding ((.), (/), id)-import Panda.Config.Global as Config+import qualified Panda.Config.Global as Config import Panda.Type.Pager as Pager import Text.RSS @@ -18,7 +18,7 @@ item_rss_template x = [ Title $ x.Post.title- , Description $ x.Post.body.markup.show+ , Description $ x.Post.body.Config.markup.show , Author $ Config.author_email , Link $ x.item_uri , PubDate $ x.Post.date @@ -32,5 +32,9 @@ , uriFragment = "" } -rss xs = RSS Config.blog_title (rss_uri Config.host_name) Config.blog_title channel_rss_template (xs.take 20 .map item_rss_template)+rss categary s xs = RSS title (rss_uri link) title channel_rss_template (xs.take 20 .map item_rss_template) .rssToXML.showXML+ where + link = Config.host_name / categary / s+ title = Config.blog_title ++ " / " ++ s+
Panda/View/Theme/BluePrint/Helper.hs view
@@ -4,7 +4,7 @@ import Panda.Helper.Env import Prelude hiding ((.), (/), id, span)-import Panda.Config.Global as Config+import qualified Panda.Config.Global as Config import qualified Panda.Type.State as State import Text.XHtml.Strict
Panda/View/Theme/BluePrint/Post.hs view
@@ -3,7 +3,7 @@ -- env import Panda.Helper.Env import Prelude hiding ((.), (/), id, span)-import Panda.Config.Global as Config+import qualified Panda.Config.Global as Config import qualified Panda.Type.State as State import Text.XHtml.Strict @@ -23,7 +23,7 @@ -- render single entry entry x = div_class "post" << [entry_title, entry_mark, entry_body] where entry_title = x.title_link- entry_body = div_class "entry" << x.Post.body.markup+ entry_body = div_class "entry" << x.Post.body.Config.markup entry_mark = p ! [theclass "small"] << [ x.blog_date, x.blog_tags ]
Panda/View/Theme/BluePrint/Search.hs view
@@ -2,7 +2,7 @@ import Panda.Helper.Env import Prelude hiding ((.), (/), id, span)-import Panda.Config.Global as Config+import qualified Panda.Config.Global as Config import qualified Panda.Type.State as State import Text.XHtml.Strict
Panda/View/Theme/BluePrint/Static.hs view
@@ -2,10 +2,10 @@ import Panda.Helper.Env import Prelude hiding ((.), (/), id, span)-import Panda.Config.Global as Config+import qualified Panda.Config.Global as Config import qualified Panda.Type.State as State import Text.XHtml.Strict import Panda.View.Theme.BluePrint.Template.Template -view tags x = x.markup.page tags+view tags x = x.Config.markup.page tags
Panda/View/Theme/BluePrint/Tag.hs view
@@ -2,7 +2,7 @@ import Panda.Helper.Env import Prelude hiding ((.), (/), id, span)-import Panda.Config.Global as Config+import qualified Panda.Config.Global as Config import qualified Panda.Type.State as State import Text.XHtml.Strict
Panda/View/Theme/BluePrint/Template/Body.hs view
@@ -3,7 +3,7 @@ -- env import Panda.Helper.Env import Prelude hiding ((.), (/), id, span)-import Panda.Config.Global as Config+import qualified Panda.Config.Global as Config import qualified Panda.Type.State as State import Text.XHtml.Strict @@ -40,20 +40,15 @@ ] navigation state = div_class "content" <<- ulist << - [ li ! [theclass ("first" ++ current_home)] << home_link- , li ! [theclass ("page_item page-item-2" ++ current_about)] << about- ]- where- nav = state.State.nav_location- current = " current_page_item"- current_home = at State.Home- current_about = at State.About- at x = if nav == x then current else ""+ ulist << Config.navigation.map (nav_item (state.State.nav_location)) +nav_item nav s = li ! [theclass (home_tag ++ "page_item" ++ current)] << link s where+ home_tag = if s == home_nav then "first " else ""+ current = if s == nav then " current_page_item" else ""+ link x = if x == home_nav then home_link else static_link x -home_link = hotlink "/" << "Home"-about = hotlink "/static/about" << "About"+home_link = hotlink "/" << home_nav+static_link s = hotlink ("/" / "static" / s) << s body_content x = div_class_id "column span-9 first" "maincontent" <<
@@ -2,12 +2,12 @@ import Panda.Helper.Env import Prelude hiding ((.), (/), id, span)-import Panda.Config.Global as Config+import qualified Panda.Config.Global as Config import qualified Panda.Type.State as State import Text.XHtml.Strict -import Panda.Config.Global as Config+import qualified Panda.Config.Global as Config html_footer = div_id "footer" << [ toHtml $ copyright
Panda/View/Theme/BluePrint/Template/Header.hs view
@@ -2,7 +2,7 @@ import Panda.Helper.Env import Prelude hiding ((.), (/), id, span)-import Panda.Config.Global as Config+import qualified Panda.Config.Global as Config import qualified Panda.Type.State as State import Text.XHtml.Strict
Panda/View/Theme/BluePrint/Template/Sidebar.hs view
@@ -2,7 +2,7 @@ import Panda.Helper.Env hiding (rss_link) import Prelude hiding ((.), (/), id, span)-import Panda.Config.Global as Config+import qualified Panda.Config.Global as Config import qualified Panda.Type.State as State import Text.XHtml.Strict @@ -26,7 +26,7 @@ rss_link state = if tagged then- let tag_name = uid.split "/".tail.first in+ let tag_name = Tag.get_name uid in link ("tag" / tag_name) tag_name else link "" "Home" where@@ -38,4 +38,4 @@ [ h2 << "Tags" , unordList $ tags.Tag.sorted.map tag_link] -tag_link x = hotlink ("/" ++ x.uid) << x.Tag.name +++ (" (" ++ x.Tag.resources.Set.size.show ++ ")")+tag_link x = hotlink ("/" ++ x.uid.urlEncode) << x.Tag.name +++ (" (" ++ x.Tag.resources.Set.size.show ++ ")")
changelog.markdown view
@@ -1,3 +1,17 @@+0.0.0.4+--------++### Features+* configurable navigation menu in `site.txt`, example: + + navigation = About, Gallery++* default values for all configurations++### Fix+* unicode support for tags+* work with the `pandoc 1.0.0.1`+ 0.0.0.3 --------
panda.cabal view
@@ -1,5 +1,5 @@ Name: panda-Version: 0.0.0.3+Version: 0.0.0.4 Build-type: Simple Synopsis: Simple Static Blog Engine Description: Simple Static Blog Engine@@ -14,7 +14,7 @@ data-files: readme.markdown, changelog.markdown library- build-depends: base, cgi, network, haskell98, pandoc >= 0.46, old-locale, old-time, directory, filepath, containers >= 0.1.0.2, mps >= 0.0, parsedate >= 3000.0.0, rss >= 3000.1.0, xhtml >= 3000.2.0.0, kibro >= 0.0, HaXml >= 1.19.4+ build-depends: base, cgi, network, haskell98, pandoc >= 1.0.0.1, old-locale, old-time, directory, filepath, containers >= 0.1.0.2, mps >= 0.0, parsedate >= 3000.0.0, rss >= 3000.1.0, xhtml >= 3000.2.0.0, kibro >= 0.0, HaXml >= 1.19.4, utf8-string >= 0.3.1 exposed-modules: Panda Panda.Controller.Application Panda.Config.Global