diff options
| author | Miguel <m.i@gmx.at> | 2019-03-07 20:22:02 +0100 |
|---|---|---|
| committer | Miguel <m.i@gmx.at> | 2019-03-07 20:22:02 +0100 |
| commit | 80b6db4bf9b39152d2169f10020be25f1b615306 (patch) | |
| tree | 18646f7512624c82df85bee0cd8105c1c60379b2 /src/WWWStaticusPlugins.hs | |
| parent | e8006ff227255a6b1a68a28313333eaacf021d29 (diff) | |
Added 'Download & Embed' Plugin
Diffstat (limited to 'src/WWWStaticusPlugins.hs')
| -rw-r--r-- | src/WWWStaticusPlugins.hs | 46 |
1 files changed, 34 insertions, 12 deletions
diff --git a/src/WWWStaticusPlugins.hs b/src/WWWStaticusPlugins.hs index 65b4e37..668dfb6 100644 --- a/src/WWWStaticusPlugins.hs +++ b/src/WWWStaticusPlugins.hs @@ -8,6 +8,7 @@ module WWWStaticusPlugins ,staticusPluginFill ,staticusPluginWrite ,staticusPluginCards + ,staticusDownloadEmbed ) where import WWWStaticus @@ -18,6 +19,7 @@ import Data.Time.Calendar import qualified Data.Map.Strict as M import qualified Data.Text as T import Control.Monad +import Data.Char import Data.Maybe import Data.Either import Data.List @@ -26,18 +28,24 @@ import Data.List.Utils import Data.Tuple.Extra import Text.Pandoc import Text.Regex +import Network.HTTP.Simple +import qualified Data.ByteString.Lazy as BL +import qualified Data.ByteString.Lazy.Char8 as Char8 --- PLUGIN IDEAS +-- IDEAS -- -- * scale images --- * pdf plugin --- * asciinema, git, videos (generate both from single one) +-- * generate mp4 from ogg/ogv -- --- * 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 --- * contact form? (use nginx log? save post request??) --- * autotranslate/ multilang +-- * tags +-- * search function +-- * generate sitemap +-- * pdf output +-- * asciinema autorecorder +-- * links checker +-- * multiple templates +-- * contact form (via nginx log?) +-- * autotranslate -- |little helper to get values out of a map easily -- error if not found. @@ -57,8 +65,9 @@ staticusPluginsDefault::[StaticusPlugin] staticusPluginsDefault=[ staticusPluginInit ,staticusPluginTimestamp ,staticusPluginCfg - ,staticusPluginCopy [".jpg",".png",".zip",".css",".js",".ico",".mp4",".ogv",".hs",".glade"] + ,staticusPluginCopy [".jpg",".png",".zip",".css",".js",".ico",".mp4",".ogv",".hs",".glade",".cast"] ,staticusPluginCards + ,staticusDownloadEmbed ,staticusPluginPandoc ,staticusPluginFill ,staticusPluginWrite @@ -77,8 +86,7 @@ staticusPluginTimestamp = StaticusPlugin "init" id runIO 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! +-- |Creates target directory and sets basic params in map. staticusPluginInit::StaticusPlugin staticusPluginInit = StaticusPlugin "init" id runIO where runIO m = @@ -92,7 +100,8 @@ staticusPluginInit = StaticusPlugin "init" id runIO let submenu= if isHome then "" else concat $ map (\x->"<li><a href=\""++htmlroot_dir++"/"++x++"/index.html\">"++cln x++"</a></li>") (menu c) let breadcrumbs=concat $ map (\(x,d)->"<li class=\"breadcrumb-item"++(if d==0 then " active" else "")++"\">"++(if d==0 then "" else "<a href=."++concat(take d (repeat "/.."))++"/index.html>")++cln x++(if d==0 then "" else "</a>")++"</li>") (zip ("home":brc) [brcl,brcl-1..]) - md <- readFile $ par "path" m++"/"++"index.md" + mdex <- doesFileExist $ par "path" m++"/"++"index.md" + md <- if mdex then readFile $ par "path" m++"/"++"index.md" else return "" tmpl <- readFile $ par "dir_in" m++"/"++"template.html" return $ M.union (M.fromList [ ("outdir",outdir) ,("index.md",md) @@ -162,6 +171,19 @@ staticusPluginWrite = StaticusPlugin "writer" id runIO writeFile ((par "outdir" m)++"/index.html") (par "final" m) return m +-- |Todo: abstract some chucker! +-- |Embed data fetched via http/https +staticusDownloadEmbed::StaticusPlugin +staticusDownloadEmbed=StaticusPlugin "download and embed" id runIO + where runIO m = do m'<-makeEmbed $ par "index.md" m + return $ M.union (M.fromList[("index.md",concat m')]) m + makeEmbed x = evr2 $ splitRegex (mkRegex "^\\{BEGIN:EMBED\\}.*$|^\\{END:EMBED\\}.*$") x + evr2 (x:y:xs) = do doc<-httpLBS $ parseRequest_ (filter (not.isControl) y) + rest<-evr2 xs + return $ x:(Char8.unpack $ getResponseBody doc):rest + evr2 x = return x + +-- |Todo: some generalized snipmate instead -- |simple bootstrap cards staticusPluginCards::StaticusPlugin staticusPluginCards = StaticusPlugin "bootstrap cards" run return |
