summaryrefslogtreecommitdiff
path: root/src/WWWStaticusPlugins.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/WWWStaticusPlugins.hs')
-rw-r--r--src/WWWStaticusPlugins.hs41
1 files changed, 34 insertions, 7 deletions
diff --git a/src/WWWStaticusPlugins.hs b/src/WWWStaticusPlugins.hs
index ccf82bc..33916ef 100644
--- a/src/WWWStaticusPlugins.hs
+++ b/src/WWWStaticusPlugins.hs
@@ -1,6 +1,7 @@
module WWWStaticusPlugins
( staticusPluginsDefault
,staticusPluginInit
+ ,staticusPluginCfg
,staticusPluginCopy
,staticusPluginPandoc
,staticusPluginFill
@@ -17,18 +18,20 @@ import Data.Either
import Data.List
import Data.List.Split
import Data.List.Utils
+import Data.Tuple.Extra
import Text.Pandoc
--
--- TODOS:
+-- 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
---
+--
-- scale images
--
-- asciinema, git, videos
@@ -36,19 +39,28 @@ import Text.Pandoc
-- contact form? (use nginx log? save post request??)
--
-- pdf plugin
+--
-- autotranslate plugin :P
--
-- |little helper to get values out of a map easily
+-- error if not found.
par k m = case M.lookup k m of
Just x -> x
Nothing -> error $ "key not found: "++k
+-- |little helper to get values out of a map easily
+-- defaulting to empty string.
+par' k m = case M.lookup k m of
+ Just x -> x
+ Nothing -> ""
+
-- |A default set of plugins that you can use to kickstart your page
-- Use now, Adapt later.
staticusPluginsDefault::[StaticusPlugin]
staticusPluginsDefault=[ staticusPluginInit
- ,staticusPluginCopy [".jpg",".png",".zip",".css",".js"]
+ ,staticusPluginCfg
+ ,staticusPluginCopy [".jpg",".png",".zip",".css",".js",".ico",".mp4",".ogv"]
,staticusPluginPandoc
,staticusPluginFill
,staticusPluginWrite
@@ -62,10 +74,10 @@ staticusPluginInit = StaticusPlugin "init" id runIO
when (not isHome) (createDirectory outdir)
c <- getDirList (par "path" m)
t <- getDirList (par "dir_in" m)
- let menutop= concat $ map (\x->"<li class=\"navitem\"><a class=\"nav-link\" href=\""++par "dir_out" m++"/"++x++"/index.html\">"++x++"</a></li>") (menu t)
- let submenu= if isHome then "" else concat $ map (\x->"<li><a href=\""++outdir++"/"++x++"/index.html\">"++x++"</a></li>") (menu c)
- let breadcrumbs=concat $ map (\x->x) brc
- let breadcrumbs=""
+ let menutop= concat $ map (\x->"<li class=\"nav-item"++(if length brc>=1 && brc!!0==x then " active" else "")++"\"><a class=\"nav-link\" href=\""++par "dir_out" m++"/"++x++"/index.html\">"++x++"</a></li>") (menu t)
+ let submenu= if isHome then "" else concat $ map (\x->"<li><a href=\""++outdir++"/"++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"
tmpl <- readFile $ par "dir_in" m++"/"++"template.html"
return $ M.union (M.fromList [ ("outdir",outdir)
@@ -74,12 +86,15 @@ staticusPluginInit = StaticusPlugin "init" id runIO
,("menutop",menutop)
,("submenu",submenu)
,("breadcrumbs",breadcrumbs)
+ ,("title",if null brc then "Home" else cln $ last brc)
]) m
where outdir = par "dir_out" m ++ "/" ++ intercalate "/" brc
brc = remUnder $ splitOn "/" (drop (length (par "dir_in" m)) (par "path" m))
+ brcl = length brc
remUnder = filter (not.null) . map (dropWhile(=='_').dropWhile(/='_'))
menu = remUnder . filter (not . isPrefixOf "00_") . map (last.splitOn "/") . sortBy (flip compare)
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.
@@ -92,6 +107,13 @@ staticusPluginCopy ext = StaticusPlugin "copy by extension" id runIO
mapM_ (\x->copyFile (par "path" m++"/"++x) (par "outdir" m++"/"++x)) dl
return m
+-- |extracts config lines (###>>>) from 'index.md'
+staticusPluginCfg::StaticusPlugin
+staticusPluginCfg = StaticusPlugin "extract config lines" run return
+ where run m = M.union (M.fromList (("index.md",indexmd):conf)) m
+ where indexmd=unlines . filter (not.isPrefixOf "###>>>") . lines $ par "index.md" m
+ conf= map (first head.second (unwords.tail).dupe.words) . filter (isPrefixOf "###>>>") . lines $ par "index.md" m
+
-- |pipes 'index.md' value through pandoc and saves in 'content'
staticusPluginPandoc::StaticusPlugin
staticusPluginPandoc = StaticusPlugin "pandoc" run return
@@ -108,6 +130,10 @@ staticusPluginFill = StaticusPlugin "fill template" run return
replace "###SUBMENU###" (par "submenu" m) $
replace "###MENU###" (par "menutop" m) $
replace "###CONTENT###" (par "content" m) $
+ replace "###ROOT###" (par "html_root" m) $
+ replace "###TITLE###" (par "title" m) $
+ replace "###DESCRIPTION###" (par' "###>>>DSC" m) $
+ replace "###KEYWORDS###" (par' "###>>>KWD" m) $
(par "template.html" m))]) m
-- |write final index.html file
@@ -116,3 +142,4 @@ staticusPluginWrite = StaticusPlugin "writer" id runIO
where runIO m = do
writeFile ((par "outdir" m)++"/index.html") (par "final" m)
return m
+