quick and dirty org2gemini script
This commit is contained in:
parent
594434aa7b
commit
22e51c3564
24
Shakefile.hs
24
Shakefile.hs
|
@ -355,26 +355,18 @@ genPdfAction _getPost out = do
|
|||
, "-o", out ]
|
||||
|
||||
|
||||
genGemini :: (MonadIO m, MonadFail m) => BlogPost -> m Text
|
||||
genGemini bp = do
|
||||
eitherMd <- liftIO $ Pandoc.runIO $ Writers.writeMarkdown def (postBody bp)
|
||||
case eitherMd of
|
||||
Left _ -> fail "BAD"
|
||||
Right innerMd -> return innerMd
|
||||
-- genGemini :: (MonadIO m, MonadFail m) => BlogPost -> m Text
|
||||
-- genGemini bp = do
|
||||
-- eitherMd <- liftIO $ Pandoc.runIO $ Writers.writeMarkdown def (postBody bp)
|
||||
-- case eitherMd of
|
||||
-- Left _ -> fail "BAD"
|
||||
-- Right innerMd -> return innerMd
|
||||
|
||||
genGeminiAction
|
||||
:: (FilePath -> Action BlogPost)
|
||||
-> [Char] -> Action ()
|
||||
genGeminiAction :: (FilePath -> Action BlogPost) -> [Char] -> Action ()
|
||||
genGeminiAction getPost out = do
|
||||
let srcFile = srcDir </> (dropDirectory1 (dropDirectory1 (out -<.> "org")))
|
||||
need [srcFile]
|
||||
bp <- getPost srcFile
|
||||
innerGemini <- genGemini bp
|
||||
let preamble = "# " <> postTitle bp <> "\n"
|
||||
<> postAuthor bp <> "\n"
|
||||
<> postDate bp <> "\n"
|
||||
<> toS origin <> toS (postUrl bp) <> "\n\n"
|
||||
writeFile' out (toS (preamble <> toS innerGemini))
|
||||
command_ [] "./engine/org2gemini.sh" [ srcFile, out ]
|
||||
|
||||
allHtmlAction :: Action ()
|
||||
allHtmlAction = do
|
||||
|
|
9
engine/org2gemini.sh
Executable file
9
engine/org2gemini.sh
Executable file
|
@ -0,0 +1,9 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
cd "$(git rev-parse --show-toplevel)" || exit 1
|
||||
|
||||
|
||||
src="$1"
|
||||
dst="$2"
|
||||
|
||||
./engine/org2gemini_step1.sh "$src" | perl -pe 's#\[\[([^]]*)\]\[([^]]*)\]\]#\n=> $1 $2#g;s#\* ##;s#=> file:#=> #g' > "$dst"
|
29
engine/org2gemini_step1.sh
Executable file
29
engine/org2gemini_step1.sh
Executable file
|
@ -0,0 +1,29 @@
|
|||
#!/usr/bin/env awk -f
|
||||
|
||||
BEGIN { IGNORECASE=1; }
|
||||
|
||||
{ skip=0; }
|
||||
|
||||
/^#+(BEGIN|END)_SRC / { gsub(/(BEGIN|END)_SRC /,"```"); }
|
||||
/^#\+TITLE: / { gsub(/^#[^:]*: /,"# "); }
|
||||
/^\* / { gsub(/^\* /,"# "); }
|
||||
/^\*\* / { gsub(/^\*\* /,"## "); }
|
||||
/^\*\*\* / { gsub(/^\*\*\* /,"### "); }
|
||||
|
||||
/^#\+(macro|lang|language|options|startup):/ { skip=1; }
|
||||
/{{{br}}}/ { gsub(/{{{br}}}/,""); }
|
||||
/{{{pemail}}}/ { gsub(/{{{pemail}}}/,"yann@esposito.host"); }
|
||||
/@@html:/ { htmlskip = 1; }
|
||||
|
||||
!skip && /^#\+([^:]*):/ {
|
||||
x=$1;
|
||||
gsub(/^#\+/,"",x);
|
||||
x=tolower(x);
|
||||
gsub(/^#\+([^:]*):/,"",$0);
|
||||
$0=x" "$0;
|
||||
}
|
||||
/^- / { gsub(/^- /,"* "); }
|
||||
!skip && !htmlskip{
|
||||
print;
|
||||
}
|
||||
/@@/ && !/@@html:/ { htmlskip = 0; }
|
Loading…
Reference in a new issue