diff options
| author | Miguel <m.i@gmx.at> | 2019-02-27 13:04:28 +0100 |
|---|---|---|
| committer | Miguel <m.i@gmx.at> | 2019-02-27 13:04:28 +0100 |
| commit | 96a8dfc44685c69c35264cd95af83d2c2c02220f (patch) | |
| tree | 20c84fccf40a197f37f8597ce80464dbcc81c703 | |
| parent | 428d1b9565cb9a7c5ea61eaaa5358354912488e8 (diff) | |
added timestamp check, to refresh only when required
| -rw-r--r-- | src/WWWStaticus.hs | 2 | ||||
| -rw-r--r-- | src/WWWStaticusPlugins.hs | 48 | ||||
| -rw-r--r-- | staticus.cabal | 1 |
3 files changed, 29 insertions, 22 deletions
diff --git a/src/WWWStaticus.hs b/src/WWWStaticus.hs index d5205f5..4259964 100644 --- a/src/WWWStaticus.hs +++ b/src/WWWStaticus.hs @@ -65,7 +65,7 @@ getDirList d = map ((d++"/")++) <$> filter (not.isPrefixOf ".") <$> listDirector -- might rely on this runPlugins::[StaticusPlugin]->FilePath->FilePath->FilePath->FilePath->IO() runPlugins plug root dir_out dir_in path = foldlM f init plug >> return () - where f m (StaticusPlugin name run runIO) = runIO m >>= return.run + where f m (StaticusPlugin name run runIO) = if M.lookup "abort" m == Nothing then runIO m >>= return.run else return m init= M.fromList [("path",path) ,("dir_in",dir_in) ,("dir_out",dir_out) diff --git a/src/WWWStaticusPlugins.hs b/src/WWWStaticusPlugins.hs index fe509f3..cc190a3 100644 --- a/src/WWWStaticusPlugins.hs +++ b/src/WWWStaticusPlugins.hs @@ -1,5 +1,6 @@ module WWWStaticusPlugins ( staticusPluginsDefault + ,staticusPluginTimestamp ,staticusPluginInit ,staticusPluginCfg ,staticusPluginCopy @@ -10,9 +11,12 @@ module WWWStaticusPlugins ) where import WWWStaticus +import System.Directory as D +import System.IO.Error +import Data.Time.Clock as C +import Data.Time.Calendar import qualified Data.Map.Strict as M import qualified Data.Text as T -import System.Directory import Control.Monad import Data.Maybe import Data.Either @@ -23,27 +27,16 @@ import Data.Tuple.Extra import Text.Pandoc import Text.Regex --- -- PLUGIN IDEAS -- --- timestamp plugin/ do not refresh if md did not change? dir timestamp? --- but check if depends on upstream stuff as git --- --- super `gallery and everythin` plugin, just throw images,videos, --- zips,tars,source files,mds etc inside a folder-> gen page! --- --- flexible layout, main pic, secondary pics, multiple templates 1 2 3 --- --- scale images --- --- asciinema, git, videos (generate both from single one) --- --- contact form? (use nginx log? save post request??) --- --- pdf plugin --- --- autotranslate/ multilang --- +-- * super `gallery and everythin` plugin, just throw images,videos, +-- zips,tars,source files,mds etc inside a folder-> gen page! +-- * flexible layout, main pic, secondary pics, multiple templates 1 2 3 +-- * scale images +-- * asciinema, git, videos (generate both from single one) +-- * contact form? (use nginx log? save post request??) +-- * pdf plugin +-- * autotranslate/ multilang -- |little helper to get values out of a map easily -- error if not found. @@ -61,6 +54,7 @@ par' k m = case M.lookup k m of -- Use now, Adapt later. staticusPluginsDefault::[StaticusPlugin] staticusPluginsDefault=[ staticusPluginInit + ,staticusPluginTimestamp ,staticusPluginCfg ,staticusPluginCopy [".jpg",".png",".zip",".css",".js",".ico",".mp4",".ogv",".hs",".glade"] ,staticusPluginCards @@ -69,13 +63,25 @@ staticusPluginsDefault=[ staticusPluginInit ,staticusPluginWrite ] +-- |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 t1 <- catchIOError (D.getModificationTime $ par "path" m++"/"++"index.md") handler + t2 <- catchIOError (D.getModificationTime $ par "outdir" m++"/"++"index.html") handler + let abort = if(t1<t2) then [("abort","yes")] else [] + when (t1<t2) $ print "result is younger.. aborting!" + return $ M.union (M.fromList abort) m + handler e = return $ UTCTime (ModifiedJulianDay 0) 1 + -- |Creates target directory and sets basic params in map: -- TODO: cleanup! staticusPluginInit::StaticusPlugin staticusPluginInit = StaticusPlugin "init" id runIO where runIO m = do putStrLn $ "processing: " ++ par "path" m ++ " ..." - when (not isHome) (createDirectory outdir) + when (not isHome) (createDirectoryIfMissing False outdir) c <- getDirList (par "path" m) t <- getDirList (par "dir_in" m) diff --git a/staticus.cabal b/staticus.cabal index e90f609..b56137c 100644 --- a/staticus.cabal +++ b/staticus.cabal @@ -31,6 +31,7 @@ library , extra , MissingH , regex-compat + , time default-language: Haskell2010 executable staticus-exe |
