From 287288f832241d5c388f8931cbcbf7b1a617f397 Mon Sep 17 00:00:00 2001 From: Miguel Date: Thu, 7 Mar 2019 22:33:26 +0100 Subject: minor cleanup --- src/WWWStaticusPlugins.hs | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'src/WWWStaticusPlugins.hs') 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 t1StaticusPlugin -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 -- cgit v1.2.3