quick and dirty org2gemini script

This commit is contained in:
Yann Esposito (Yogsototh) 2020-11-08 21:38:58 +01:00
parent 594434aa7b
commit 22e51c3564
Signed by untrusted user who does not match committer: yogsototh
GPG Key ID: 7B19A4C650D59646
3 changed files with 46 additions and 16 deletions

View File

@ -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
View 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
View 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; }