summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMiguel <m.i@gmx.at>2019-02-18 17:35:09 +0100
committerMiguel <m.i@gmx.at>2019-02-18 17:35:09 +0100
commit3366fb07342249ccd9037ac487205058c88fabc4 (patch)
treef5fcd311663e055626f9b2b92b2d43210ce021e4 /src
parent217208e3f342d31da541b88af8d06aabbf322f86 (diff)
something useful
Diffstat (limited to 'src')
-rw-r--r--src/WWWStaticus.hs12
-rw-r--r--src/WWWStaticusPlugins.hs41
2 files changed, 41 insertions, 12 deletions
diff --git a/src/WWWStaticus.hs b/src/WWWStaticus.hs
index 2144fe0..d5205f5 100644
--- a/src/WWWStaticus.hs
+++ b/src/WWWStaticus.hs
@@ -21,9 +21,10 @@ import Data.List
-- |Runs WWWStaticus given an input and an output directory and a list of
-- plugins. This traverses 'inp' recursively and runs all the plugins
--- 'one by one' in each subdirectory recursively.
-runStaticus :: FilePath->FilePath->[StaticusPlugin]->IO()
-runStaticus inp outp plug= trvDirTree inp (runPlugins plug outp)
+-- 'one by one' in each subdirectory recursively. 'root' is the html root
+-- directory used in links etc.
+runStaticus :: FilePath->FilePath->FilePath->[StaticusPlugin]->IO()
+runStaticus inp outp root plug= trvDirTree inp (runPlugins plug root outp)
-- |The following structure represents a single WWWStaticus plugin.
-- A plugin is defined by a Name and two functions one pure and one that
@@ -62,10 +63,11 @@ getDirList d = map ((d++"/")++) <$> filter (not.isPrefixOf ".") <$> listDirector
-- |run plugins in a single directory 'path'.
-- 'dir_in' and 'dir_out' have to be provided as well, since plugins
-- might rely on this
-runPlugins::[StaticusPlugin]->FilePath->FilePath->FilePath->IO()
-runPlugins plug dir_out dir_in path = foldlM f init plug >> return ()
+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
init= M.fromList [("path",path)
,("dir_in",dir_in)
,("dir_out",dir_out)
+ ,("html_root",root)
,("log","run plugins at: "++path++"\n")]
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
+