From 96a8dfc44685c69c35264cd95af83d2c2c02220f Mon Sep 17 00:00:00 2001 From: Miguel Date: Wed, 27 Feb 2019 13:04:28 +0100 Subject: added timestamp check, to refresh only when required --- src/WWWStaticus.hs | 2 +- src/WWWStaticusPlugins.hs | 48 ++++++++++++++++++++++++++--------------------- 2 files changed, 28 insertions(+), 22 deletions(-) (limited to 'src') 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