diff options
Diffstat (limited to 'src/WWWStaticusPlugins.hs')
| -rw-r--r-- | src/WWWStaticusPlugins.hs | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/src/WWWStaticusPlugins.hs b/src/WWWStaticusPlugins.hs index 043e40e..4ecbdb8 100644 --- a/src/WWWStaticusPlugins.hs +++ b/src/WWWStaticusPlugins.hs @@ -35,7 +35,6 @@ import qualified Data.ByteString.Lazy.Char8 as Char8 -- IDEAS -- --- * scale images -- * generate mp4 from ogg/ogv -- -- * tags @@ -66,7 +65,7 @@ staticusPluginsDefault::[StaticusPlugin] staticusPluginsDefault=[ staticusPluginInit ,staticusPluginTimestamp ,staticusPluginCfg - ,staticusPluginCopy [".jpg",".png",".zip",".css",".js",".ico",".mp4",".ogv",".hs",".glade",".cast",".pdf"] + ,staticusPluginCopy [".jpg",".png",".zip",".css",".js",".ico",".mp4",".ogv",".hs",".glade",".cast",".pdf"] "640x480" ,staticusPluginCards ,staticusDownloadEmbed ,staticusPluginPandoc @@ -75,16 +74,15 @@ staticusPluginsDefault=[ staticusPluginInit ] -- |Check if result is younger than source index.md, otherwise set "abort" --- TODO: what if other things changed (some upstream files in worst case or even subdir added/removed) staticusPluginTimestamp::StaticusPlugin staticusPluginTimestamp = StaticusPlugin "init" id runIO where runIO m = - do t0 <- catchIOError (D.getModificationTime $ par "path" m) handler - t1 <- catchIOError (D.getModificationTime $ par "path" m++"/"++"index.md") handler - t2 <- catchIOError (D.getModificationTime $ par "outdir" m++"/"++"index.html") handler + do t0 <- getT $ par "path" m + t1 <- getT $ par "path" m++"/"++"index.md" + t2 <- getT $ par "outdir" m++"/"++"index.html" let abort = if(max t0 t1<t2) then [("abort","yes")] else [] - when (max t0 t1<t2) $ print "result is younger.. aborting!" return $ M.union (M.fromList abort) m + getT v = catchIOError (D.getModificationTime $ v) handler handler e = return $ UTCTime (ModifiedJulianDay 0) 1 -- |Creates target directory and sets basic params in map. @@ -125,9 +123,10 @@ staticusPluginInit = StaticusPlugin "init" id runIO -- |This plugin will simply copy files of given extension from source -- to the target directory. give it a list of file extensions. --- example [".png",".zip",".css"] -staticusPluginCopy::[String]->StaticusPlugin -staticusPluginCopy ext = StaticusPlugin "copy by extension" id runIO +-- It will also scale all .png and .jpg files to fit in the given dims +-- example [".png",".zip",".css"] "640x480" +staticusPluginCopy::[String]->String->StaticusPlugin +staticusPluginCopy ext dims = StaticusPlugin "copy by extension" id runIO where runIO m = do let tst x=or $ map ($x) (map isSuffixOf ext) let tst_img x=or $ map ($x) (map isSuffixOf [".jpg",".png"]) @@ -136,7 +135,7 @@ staticusPluginCopy ext = StaticusPlugin "copy by extension" id runIO mapM_ (\x->copyFile (par "path" m++"/"++x) (par "outdir" m++"/"++x)) dl mapM_ (\x->scaleFile (par "path" m++"/"++x) (par "outdir" m++"/"++x)) $ filter tst_img dl return m - where scaleFile fin fout = do let conv_cmd = "convert \""++fin++"\" -resize 640x640 \""++renameImg fout++"\"" + where scaleFile fin fout = do let conv_cmd = "convert \""++fin++"\" -resize "++dims++" \""++renameImg fout++"\"" putStrLn conv_cmd system conv_cmd renameImg = uncurry (++) . first (("/"++).intercalate "/". init) . second (("/scale_"++).last) . dupe . splitOn "/" @@ -178,7 +177,7 @@ staticusPluginWrite = StaticusPlugin "writer" id runIO writeFile ((par "outdir" m)++"/index.html") (par "final" m) return m --- |Todo: abstract some chucker! +-- |Todo: abstract some chucker for this plugin and others! -- |Embed data fetched via http/https staticusDownloadEmbed::StaticusPlugin staticusDownloadEmbed=StaticusPlugin "download and embed" id runIO |
