[tags and stuff jupdike@gmail.com**20080220171057] { hunk ./ANSI.hs 66 + + toEnum _ = error "Highlight: toEnum not implemented" hunk ./Template.hs 74 -editBtn p = makeFlipper "edit2" ("/index.cgi?action=edit&page=" ++ p) +editBtn p = makeFlipper "edit2" ("/index.cgi?action=edit&page=" ++ p ++ "#Bottom") hunk ./Template.hs 347 - xhiddens = [hiddeninput "action" "modify", - hiddeninput "page" page] + xhiddens = [ hiddeninput "action" "modify", + hiddeninput "page" page, + "a" `with` ["name"-->"Bottom"] ] hunk ./Template.hs 426 - -- read in the input file or stdin if filename is - - s <- if filename=="-" then getContents else readFile filename + -- read in the input file or stdin if filename is - or lop off - if there are more characters and use the tail as the string, i.e. -text data + s <- if filename=="-" then getContents else (if head filename == '-' then return (tail filename) else readFile filename) hunk ./index.hs 1 +{- # O P T I O N S _ GHC -fglasgow-exts # -} + hunk ./index.hs 22 +data Eq a => BoolOp a = Has a | And [BoolOp a] | Or [BoolOp a] | Not (BoolOp a) deriving (Show, Eq) + hunk ./index.hs 274 +toFunc :: Eq a => (a -> a) -> BoolOp a -> [a] -> Bool +toFunc f boolop tags = fnFromBoolOp boolop tags where + fnFromBoolOp (Has x ) y = f x `elem` y + fnFromBoolOp (Not x ) y = not (fnFromBoolOp x y) + fnFromBoolOp (And xs) y = and [fnFromBoolOp x y | x <- xs] + fnFromBoolOp (Or xs) y = or [fnFromBoolOp x y | x <- xs] + +getAllFilesTags :: IO [(String, [String])] +getAllFilesTags = do + allfiles <- getDirectoryContents root + let files = [x | x <- allfiles, x `endsWith` ".tags"] + contentses <- mapM (\ file -> readFile (root++file)) files + return [(reverse (reverse file `dropping` reverse ".tags"), lines cnts) + | (file,cnts) <- zip files contentses] + +procTags env = do + let page = dlookup "all" "page" env + let loggedin :: Bool ; loggedin = read $ dlookup "False" "loggedin" env + let boolop = And (let hide = (if loggedin then [] else [Not (Has "hidden"), Not (Has "system")]) + in if map toLower page == "all" + then hide + else [Has page] ++ hide) + let tagsPred = toFunc (map toLower) boolop + allFilesTags <- getAllFilesTags + let files = [filename | (filename, tags) <- allFilesTags, tagsPred tags] + putStr httpheader + let result = "==== "++page++"\n" ++ + concatMap (\file->"- [[lnk:/articles/"++file++" "++(tagdecode file)++"]]\n") files + template loggedin "" "Home" root ('-':result) -- ("-==== "++page++"\n") --(root++"Home.txt") + + +-- template loggedin "" page root (root++"Home.txt") -- ('-':result) -- (root++"Home.txt") +-- putStrLn $ show files +-- + hunk ./index.hs 342 - ("rename", procRename), ("movepage", procMovepage)] + ("rename", procRename), ("movepage", procMovepage), ("tags", procTags)] }