mirror of
https://github.com/simonmichael/hledger.git
synced 2024-11-08 07:09:28 +03:00
e1c9e51775
Goal: Generate man pages and web docs from one source. Current plan: The master docs for each package are now the pandoc-style manpage-markdown files in the package directories - hledger/hledger.1.md, hledger-lib/hledger_journal.5.md, etc. Parts of these will be marked as web-only, and parts as man-only, using divs recognisable by custom pandoc filters. When generating man pages we strip the web-only parts, and all html blocks, inline html and hyperlinks. When generating web docs we strip the man-only parts and apply any other tweaks needed for easy presentation, perhaps combining them into a single web page similar to the old user manual. Shake: This was hard to do with GNU Make, and so I've introduced Shake, which is working very well. Both coexist for now but it's probably time to switch.
103 lines
3.0 KiB
Haskell
Executable File
103 lines
3.0 KiB
Haskell
Executable File
#!/usr/bin/env stack
|
|
-- stack runghc --package shake
|
|
|
|
import Development.Shake
|
|
import Development.Shake.FilePath
|
|
import Data.List
|
|
import System.Directory as S (getDirectoryContents)
|
|
|
|
manpages :: [String]
|
|
manpages = [
|
|
"hledger_csv.5"
|
|
,"hledger_journal.5"
|
|
,"hledger_timedot.5"
|
|
,"hledger_timelog.5"
|
|
,"hledger.1"
|
|
,"hledger-api.1"
|
|
,"hledger-ui.1"
|
|
,"hledger-web.1"
|
|
]
|
|
|
|
manpageDir :: String -> FilePath
|
|
manpageDir p
|
|
| '_' `elem` p = "hledger-lib"
|
|
| otherwise = dropExtension p
|
|
|
|
buildDir :: FilePath
|
|
buildDir = ".build"
|
|
|
|
main :: IO ()
|
|
main = do
|
|
|
|
pandocFilters <-
|
|
map ("tools" </>). nub . sort . map (-<.> "") . filter ("pandoc" `isPrefixOf`)
|
|
<$> S.getDirectoryContents "tools"
|
|
|
|
-- man pages, still markdown but with man-only sections removed.
|
|
-- (We let hakyll do the html rendering since it's good
|
|
-- at applying the site style, table of contents etc.)
|
|
let manpageFilteredMds = ["site" </> p <.>".md" | p <- manpages]
|
|
|
|
-- man pages, converted to man nroff with web-only sections removed
|
|
let manpageNroffs = [manpageDir p </> p | p <- manpages]
|
|
|
|
shakeArgs shakeOptions{shakeFiles=buildDir} $ do
|
|
|
|
want $ manpageNroffs ++ manpageFilteredMds
|
|
|
|
manpageNroffs |%> \out -> do
|
|
let
|
|
md = out <.> "md"
|
|
tmpl = "doc/manpage.nroff"
|
|
need $ md : tmpl : pandocFilters
|
|
cmd "pandoc" md "--to man -s --template" tmpl
|
|
-- XXX assume these are compiled
|
|
"--filter tools/pandocRemoveHtmlBlocks"
|
|
"--filter tools/pandocRemoveHtmlInlines"
|
|
"--filter tools/pandocRemoveLinks"
|
|
"--filter tools/pandocRemoveNotes"
|
|
"--filter tools/pandocCapitalizeHeaders"
|
|
"-o" out
|
|
|
|
manpageFilteredMds |%> \out -> do
|
|
let
|
|
p = dropExtension $ takeFileName out
|
|
md = manpageDir p </> p <.> "md"
|
|
tmpl = "doc/manpage.html"
|
|
need $ md : tmpl : pandocFilters
|
|
cmd "pandoc" md "--to markdown"
|
|
-- XXX assume this is compiled
|
|
"--filter tools/pandocRemoveManonlyBlocks"
|
|
"-o" out
|
|
|
|
pandocFilters |%> \out -> do
|
|
need [out <.> "hs"]
|
|
cmd "stack ghc" out
|
|
|
|
phony "clean" $ do
|
|
putNormal "Cleaning generated files"
|
|
removeFilesAfter "" manpageNroffs
|
|
removeFilesAfter "" manpageFilteredMds
|
|
putNormal "Cleaning object files"
|
|
removeFilesAfter "tools" ["*.o","*.p_o","*.hi"]
|
|
putNormal "Cleaning shake build files"
|
|
removeFilesAfter buildDir ["//*"]
|
|
|
|
-- manpageHtmls |%> \out -> do
|
|
-- let
|
|
-- p = dropExtension $ takeFileName out
|
|
-- md = manpageDir p </> p <.> "md"
|
|
-- tmpl = "doc/manpage.html"
|
|
-- need [md, tmpl]
|
|
-- cmd "pandoc" md "--to html --filter tools/pandocRemoveManpageBlocks.hs --template" tmpl "-o" out
|
|
|
|
-- "site/manual2.html" %> \out -> do
|
|
-- need ["site/manual2.md"]
|
|
-- cmd "pandoc site/manual2.md -o" out
|
|
|
|
-- "_build//*.o" %> \out -> do
|
|
-- let c = dropDirectory1 $ out -<.> "c"
|
|
-- let m = out -<.> "m"
|
|
-- () <- cmd "gcc -c" [c] "-o" [out] "-MMD -MF" [m]
|
|
-- needMakefileDependencies m
|