diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/WWWStaticusPlugins.hs | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/src/WWWStaticusPlugins.hs b/src/WWWStaticusPlugins.hs index 4ecbdb8..2b376ad 100644 --- a/src/WWWStaticusPlugins.hs +++ b/src/WWWStaticusPlugins.hs @@ -15,6 +15,7 @@ import WWWStaticus import System.Process import System.Directory as D import System.IO.Error +import System.FilePath import Data.Time.Clock as C import Data.Time.Calendar import qualified Data.Map.Strict as M @@ -121,24 +122,27 @@ staticusPluginInit = StaticusPlugin "init" id runIO isHome = par "path" m==par "dir_in" m cln x = replace "-" " " x --- |This plugin will simply copy files of given extension from source --- to the target directory. give it a list of file extensions. --- It will also scale all .png and .jpg files to fit in the given dims --- example [".png",".zip",".css"] "640x480" + +-- |This plugin will: +-- +-- 1) copy files of given extension from source to the target directory. +-- 2) create scaled versions of all .png and .jpg files to fit in the given dims. (using convert) +-- 3) create mp4 version of ogv/ogg files. (using ffmpeg) +-- +-- Example Params [".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"]) - let tst_vid x=or $ map ($x) (map isSuffixOf [".ogv",".ogg"]) - dl <- filter tst <$> listDirectory (par "path" m) - 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 "++dims++" \""++renameImg fout++"\"" - putStrLn conv_cmd - system conv_cmd - renameImg = uncurry (++) . first (("/"++).intercalate "/". init) . second (("/scale_"++).last) . dupe . splitOn "/" +staticusPluginCopy ext dims = StaticusPlugin "Copy and More" id runIO + where runIO m = do dl <- listDirectory (par "path" m) + mapM_ (work dl m) [(copyFile,ext), (scaleFile, [".jpg",".png"]), (videoFile,[".ogv",".ogg"])] + return m + work dl m (f,exts) = mapM_ (\x->f (par "path" m++"/"++x) (par "outdir" m++"/"++x)) $ extFilter exts dl + extFilter ext = filter f where f x=or $ map ($x) (map isSuffixOf ext) + scaleFile = systemExe renImg "convert" "" ("-resize "++dims) + videoFile = systemExe (flip (-<.>) ".mp4") "ffmpeg" "-i" "" + renImg = uncurry replaceFileName . second (("scale_"++).takeFileName) . dupe + systemExe renOut cmd fl1 fl2 f1 f2 = void $ system $ intercalate " " [cmd,fl1,qt f1,fl2,qt $ renOut f2] + qt = ('\"':).(++"\"") -- |extracts config lines (###>>>) from 'index.md' staticusPluginCfg::StaticusPlugin |
