panda 2008.10.12 → 2008.10.13
raw patch · 17 files changed
+91/−37 lines, 17 files
Files
- Panda/Config/Global.hs +13/−1
- Panda/Controller/Application.hs +20/−15
- Panda/Helper/Helper.hs +3/−2
- Panda/Helper/StateHelper.hs +18/−0
- Panda/View/Atom/Comment.hs +2/−1
- Panda/View/Atom/Post.hs +3/−2
- Panda/View/Atom/Tag.hs +3/−1
- Panda/View/Control/Helper.hs +3/−2
- Panda/View/Control/Search.hs +2/−1
- Panda/View/Control/Tag.hs +3/−1
- Panda/View/Widget/Header.hs +1/−1
- Panda/View/Widget/Navigation.hs +2/−2
- Panda/View/Widget/RSS.hs +3/−3
- Panda/View/Widget/SearchBar.hs +3/−1
- Panda/View/Widget/Sidebar.hs +3/−3
- changelog.markdown +7/−0
- panda.cabal +2/−1
Panda/Config/Global.hs view
@@ -1,7 +1,15 @@ module Panda.Config.Global where -import Panda.Helper.Env+import Panda.Helper.Helper+import MPS import Prelude hiding ((.), (/), (^), id, readFile)++import System.FilePath hiding ((<.>))+import System.IO.UTF8 (readFile, writeFile)+import Control.Arrow ((>>>), (&&&), (***))+import Data.Maybe+import System.Directory+ import Panda.Type.Reader import Panda.Type.Sidebar import Panda.Type.Theme@@ -44,6 +52,10 @@ navigation = config_for' "navigation" "About" .parse_config.("Home" :) panda_url = "http://github.com/nfjinjing/panda"+root + | user_root.belongs_to ["/", ""] = "/"+ | otherwise = user_root.("/" /).remove_trailing_slash+ where user_root = config_for' "root" "/" default_reader = Markdown
Panda/Controller/Application.hs view
@@ -13,6 +13,7 @@ -- env import Panda.Helper.Env hiding (tag)+import Panda.Helper.StateHelper import Prelude hiding ((.), (/), (^), id) import qualified Panda.Type.State as S import qualified Panda.Config.Global as G@@ -32,22 +33,26 @@ import qualified Panda.View.Control.Search as SearchV import qualified Panda.View.Widget.RSS as RSSV -blog_regex = "^/[0-9][0-9]-[0-9][0-9]-[0-9][0-9]"- +per_page = G.per_page+root = G.root++blog_regex = "[0-9][0-9]-[0-9][0-9]-[0-9][0-9]" pages = - [ ("^/$" ,index )- , ("^/([?].+$)?$" ,index )- , ("^/rss.xml$" ,index_feed )- , (blog_regex ,blog )- , ("^/static/." ,static )- , ("^/tag/.*/rss.xml$" ,tag_feed )- , ("^/tag/." ,tag )- , ("^/search" ,search )- , ("^/comment/create" ,comment_create )- ]+ [ ("$" ,index )+ , ("([?].+$)?$" ,index )+ , ("rss.xml$" ,index_feed )+ , (blog_regex ,blog )+ , ("static/." ,static )+ , ("tag/.*/rss.xml$" ,tag_feed )+ , ("tag/." ,tag )+ , ("search" ,search )+ , ("comment/create" ,comment_create )+ ] .map_fst ((root /) >>> ("^" ++))+ +++ [ ("^" ++ root ++ "$" ,index )] -per_page = G.per_page + index = do blogs <- Post.list.liftIO p <- paginate per_page $ blogs.length@@ -64,7 +69,7 @@ blogs.RSSV.rss "" "" .output blog = do- id <- uri ^ ("blog/" ++)+ id <- uri ^ ( "blog" / ) blog <- Post.get id .liftIO comments <- Comment.list_for id .liftIO tags <- Tag.list.liftIO@@ -131,7 +136,7 @@ inputs >>= (Comment.create >>> liftIO) else return ()- redirect $ ("/" ++ post_id.id_to_resource.to_utf8).urlEncode+ redirect $ (G.root / post_id.id_to_resource.to_utf8).urlEncode -- create helper, should be refactored to some common aspect
Panda/Helper/Helper.hs view
@@ -19,6 +19,7 @@ import Prelude hiding ((.), (/), (^), id) import Char import Data.List+import qualified Data.List as L import Panda.Type.Reader import System.FilePath.Posix hiding ((<.>)) @@ -32,8 +33,8 @@ take_extension = takeExtension >>> split "\\." >>> last -- controller-uri = requestURI ^ (uriPath >>> urlDecode >>> tail >>> remove_trailing_slash >>> from_utf8 )- where remove_trailing_slash s = if s.last.is '/' then s.init else s+raw_uri = requestURI ^ (uriPath >>> urlDecode >>> tail >>> remove_trailing_slash >>> from_utf8 )+remove_trailing_slash s = if s.last.is '/' then s.init else s params = do query_string <- requestURI ^ uriQuery
+ Panda/Helper/StateHelper.hs view
@@ -0,0 +1,18 @@+{-# OPTIONS -fno-monomorphism-restriction #-}++module Panda.Helper.StateHelper where++import Panda.Helper.Env+import qualified Panda.Config.Global as G+import Prelude hiding ((.), (/), (^), id)++-- G.root = /blog+-- raw_uri = blog/x+-- full_uri = /blog/x+-- uri = full_uri - (/blog/)+remove_root s+ | G.root.is "/" = s+ | otherwise = s.slice (G.root.length) (s.length)++uri = raw_uri ^ remove_root+-- uri = raw_uri
Panda/View/Atom/Comment.hs view
@@ -2,6 +2,7 @@ import Panda.Helper.Env hiding (title, date) import Prelude hiding ((.), (/), (^), id, span)+import qualified Panda.Config.Global as G -- view import qualified Panda.View.Atom.Tag as Tag@@ -31,7 +32,7 @@ create x = toHtml [ h2 ! [id "respond"] << "Leave a Response"- , gui "/comment/create" ! [id "commentform"] <<+ , gui (G.root / "comment/create") ! [id "commentform"] << [ field "author" 22 1 "Name (required)" , field "url" 22 2 "Website" , field "human-hack" 22 3 "What is 5 + 5 ?"
Panda/View/Atom/Post.hs view
@@ -2,6 +2,7 @@ import Panda.Helper.Env hiding (name, title, date) import Prelude hiding ((.), (/), (^), id, span)+import qualified Panda.Config.Global as G -- view import qualified Panda.View.Atom.Tag as Tag@@ -20,11 +21,11 @@ entry_mark = p ! [theclass "small"] << [ blog_date, blog_tags, blog_comments ].map (send_to x) title_link x = h2 << hotlink (entry_uri x) << x.title-entry_uri x = "/" ++ uid x .id_to_resource+entry_uri x = G.root / ( uid x .id_to_resource ) blog_date x = toHtml $ x.date.formatCalendarTime defaultTimeLocale "%b %e, %Y" blog_tags x | x.tags.null = toHtml "" blog_tags x = " | " +++ "Published in " +++ x.tags.map Tag.tag_link .intersperse (", ".toHtml) blog_comments x | x.comment_size.is 0 = toHtml ""-blog_comments x = " | " +++ hotlink (entry_uri x / "#comments") << (x.comment_size.show ++ " Comments")+blog_comments x = " | " +++ hotlink ( entry_uri x / "#comments") << (x.comment_size.show ++ " Comments")
Panda/View/Atom/Tag.hs view
@@ -2,9 +2,11 @@ import Panda.Helper.Env hiding (name) import Panda.Model.Tag+import qualified Panda.Config.Global as G+import Prelude hiding ((/)) instance DataRenderer Tag where render_data = name >>> tag_link -tag_link s = toHtml $ hotlink ("/tag/" ++ s ) << s +tag_link s = toHtml $ hotlink (G.root / "tag" / s ) << s
Panda/View/Control/Helper.hs view
@@ -4,6 +4,7 @@ import Prelude hiding ((.), (/), (^), id, span) import Panda.Type.Pager as Pager+import qualified Panda.Config.Global as G nav p r = @@ -12,12 +13,12 @@ ] nav_previous p r = if p.Pager.has_previous - then toHtml $ hotlink ( r' ++ "page=" ++ p.Pager.previous.show ) << previous_sign+ then toHtml $ hotlink ( G.root ++ r' ++ "page=" ++ p.Pager.previous.show ) << previous_sign else spaceHtml where r' = if isSuffixOf "&" r then r else r ++ "?" nav_next p r = if p.Pager.has_next- then toHtml $ hotlink ( r' ++ "page=" ++ p.Pager.next.show ) << next_sign+ then toHtml $ hotlink ( G.root ++ r' ++ "page=" ++ p.Pager.next.show ) << next_sign else spaceHtml where r' = if isSuffixOf "&" r then r else r ++ "?"
Panda/View/Control/Search.hs view
@@ -3,12 +3,13 @@ import Panda.Helper.Env import Prelude hiding ((.), (/), (^), id, span) import qualified Panda.Type.State as State+import qualified Panda.Config.Global as G -- view import Panda.View.Atom.Post import Panda.View.Control.Helper import Panda.View.Widget.Template -view state s = for_current_page p >>> map render_data >>> (+++ nav p ("/search" ++ "?s=" ++ s ++ "&")) >>> page state+view state s = for_current_page p >>> map render_data >>> (+++ nav p ( (G.root / "search") ++ "?s=" ++ s ++ "&")) >>> page state where p = state.State.pager
Panda/View/Control/Tag.hs view
@@ -3,13 +3,15 @@ import Panda.Helper.Env import Prelude hiding ((.), (/), (^), id, span) import qualified Panda.Type.State as State+import qualified Panda.Config.Global as G -- view import Panda.View.Atom.Post import Panda.View.Control.Helper import Panda.View.Widget.Template -view state = for_current_page p >>> map render_data >>> (+++ nav p ("/" ++ tag_id)) >>> page state++view state = for_current_page p >>> map render_data >>> (+++ nav p ( G.root / tag_id)) >>> page state where p = state.State.pager tag_id = state.State.uid
Panda/View/Widget/Header.hs view
@@ -12,7 +12,7 @@ ] site_name = toHtml $- [ toHtml $ hotlink "/" ! [theclass "logo"] << ""+ [ toHtml $ hotlink G.root ! [theclass "logo"] << "" , h1 << G.blog_title , div_class "description" << G.blog_subtitle ]
@@ -15,5 +15,5 @@ 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_nav-static_link s = hotlink ("/" / "static" / s) << s.dropExtension+home_link = hotlink G.root << home_nav+static_link s = hotlink (G.root / "static" / s) << s.dropExtension
Panda/View/Widget/RSS.hs view
@@ -12,7 +12,7 @@ import Panda.Model.Post as Post -entry_uri x = "/" ++ Post.uid x.split "/".tail.join "/"+entry_uri x = G.root ++ Post.uid x.split "/".tail.join "/" -- RSS channel_rss_template = [ RSS.Language "en-us" ]@@ -26,11 +26,11 @@ ] item_uri x = nullURI { uriScheme = "http://", uriPath = G.host_name ++ x.entry_uri }-rss_uri x = nullURI { uriScheme = "http://", uriPath = x / "rss.xml" }+rss_uri x = nullURI { uriScheme = "http://", uriPath = G.root / x / "rss.xml" } rss categary s xs = RSS title (rss_uri link) title channel_rss_template (xs.take 20 .map item_rss_template) .rssToXML.showXML where - link = G.host_name / categary / s+ link = G.host_name / G.root / categary / s title = G.blog_title ++ " / " ++ s
Panda/View/Widget/SearchBar.hs view
@@ -1,5 +1,7 @@ module Panda.View.Widget.SearchBar where import Panda.Helper.Env hiding (header)+import qualified Panda.Config.Global as G+import Prelude hiding ((/)) -search_bar = div_id "search" << form ! [action "/search", method "get"] << thediv << textfield "s"+search_bar = div_id "search" << form ! [action (G.root / "search"), method "get"] << thediv << textfield "s"
Panda/View/Widget/Sidebar.hs view
@@ -32,15 +32,15 @@ if tagged then let tag_name = Tag.get_name uid in- link ("tag" / tag_name) tag_name+ link ( "tag" / tag_name) tag_name else link "" "Home" where uid = State.uid state tagged = uid.match "^tag/.+" .isJust- link r s = hotlink ("/" / r / "rss.xml") ! [ theclass "feedlink" ] << s+ link r s = hotlink (G.root / r / "rss.xml") ! [ theclass "feedlink" ] << s tag_list tags = toHtml [ h2 << "Tags" , unordList $ tags.Tag.sorted.map tag_link] -tag_link x = ( hotlink ("/" ++ x.Tag.uid) << x.Tag.name ) +++ ( " (" ++ x.Tag.resources.Set.size.show ++ ")" )+tag_link x = ( hotlink (G.root / x.Tag.uid) << x.Tag.name ) +++ ( " (" ++ x.Tag.resources.Set.size.show ++ ")" )
changelog.markdown view
@@ -1,3 +1,10 @@+2008.10.13+-----------++### Feature++* configurable root_path for `hostname/blog` + 2008.10.12 ----------
panda.cabal view
@@ -1,5 +1,5 @@ Name: panda-Version: 2008.10.12+Version: 2008.10.13 Build-type: Simple Synopsis: A simple static blog engine Description: A simple static blog engine@@ -24,6 +24,7 @@ Panda.Helper.Env Panda.Helper.Helper+ Panda.Helper.StateHelper Panda.Model.Comment Panda.Model.Post