[Fencommits] fenserve: for pages, show the number of descendants and levels
Tuukka Hastrup
Tuukka.Hastrup at iki.fi
Tue May 1 22:43:03 EEST 2007
Tue May 1 22:42:16 EEST 2007 Tuukka Hastrup <Tuukka.Hastrup at iki.fi>
* for pages, show the number of descendants and levels
diff -rN -u old-fenserve/notetaker/Main.hs new-fenserve/notetaker/Main.hs
--- old-fenserve/notetaker/Main.hs 2007-05-01 22:43:03.000000000 +0300
+++ new-fenserve/notetaker/Main.hs 2007-05-01 22:43:03.000000000 +0300
@@ -66,9 +66,14 @@
renderNote p (Note title False cs) = "<li>" ++ title ++ renderNotes p nick cs
renderNote p (Note title True cs) =
"<li>" ++ title ++ " (<a href='/item/"
- ++ renderPath p ++ "?nick=" ++ nick ++ "'><i>" ++ c ++ "</i></a>)"
- where l = length cs; c = if l==1 then "1 child" else show l++" children"
-
+ ++ renderPath p ++ "?nick=" ++ nick ++ "'><i>"
+ ++ countable (length cs) "child" "ren" ++ "</i></a>, "
+ ++ countable (gather ((+1) . sum) 1 cs - 1) "descendant" "s" ++ ", "
+ ++ countable (gather ((+1) . maximum) 0 cs) "level" "s" ++ ")"
+ where countable 1 s _ = "1 " ++ s
+ countable n s pl = printf "%s %s%s" (show n) s pl
+ gather _ leaf [] = leaf
+ gather op leaf cs = op $ map (\(Note _ _ x) -> gather op leaf x) cs
readPath :: String -> Path
readPath s = readPath' s 0 (\p _ -> p)
More information about the Fencommits
mailing list