blog with asciidoc

blog with asciidoc

I like MD, but ASCIIDOC is my (current) favorite markup. I really need to be able to write my blog with asciidoc, then publish the HTML web page — these can/should be automated in VIM.

"Asciidoc2Jekyll

function s:esctitle(str)
  let str = a:str
  let str = tolower(str)
  let str = substitute(str, g:jekyll_title_pattern, '-', 'g')
  let str = substitute(str, '\(--\)\+', '-', 'g')
  let str = substitute(str, '\(^-\|-$\)', '', 'g')
  return str
endfunction

"(02/20/2013) publish a asciidoc-generated html blog
function! Asciidoc2Jekyll(leveloffset, title)
    let os=a:leveloffset
    let title=a:title

    if title == ''
      let title = input("Post title: ")
    endif

    if title != ''
        let file_name = strftime("%Y-%m-%d-") .
           \s:esctitle(title) .
           \"." . "html"

        "exe "tabedit " . g:jekyll_path . "/_posts/" . file_name
        let full_name = g:jekyll_path . "/_posts/" . file_name

        let g:AsciidocCmd = ":0,\$w !asciidoc
            \-a numbered -a toc2
            \-a toclevels=4
            \-a iconsdir=/home/ping/bin/asciidoc-8.6.8/images/icons
            \-a icons -a data-uri -a showcomments
            \-o " . full_name . " " . "
            \-a leveloffset=" . os . "@" . " " . "
            \-b bootstrap-docs - "

        echo "the follow CLI will be executed\n" g:AsciidocCmd

        let isSure=input("are you sure?(y/n)",'y')
        if isSure == 'y'
            exec g:AsciidocCmd
        else
            return g:AsciidocCmd
        endif
    endif
endf

command! -nargs=* A2J :call Asciidoc2Jekyll(<f-args>)
nn <expr> ,aj ':' . Asciidoc2Jekyll(-1, "new_post") . repeat("\<left>", 24)

"git

"todo: need to return the cmd but "not" to excute
function! MyGit(commitmsg)
    let commitmsg=a:commitmsg
    let GitCmd=":!
        \git add -A .;
        \git commit -m \"" .
        \commitmsg . "\";" . "
        \git push origin master"
        "\repeat("\<left>", 30)
    return ":" . GitCmd
endf
command! -nargs=* MyGit exec MyGit(<q-args>)

"command! -nargs=* MyGit  call MyGit(<q-args>)

"this works, but too ugly
"nn ,gg :!git add -A .;git commit -m "msg: ";git push origin master"
"            \<left><left><left><left><left><left><left>
"            \<left><left><left><left><left><left><left>
"            \<left><left><left><left><left><left><left>
"            \<left><left><left><left><left>
"this is much better
nn <expr> ,gg ':' . MyGit("new post:") . repeat("\<left>", 24)
  • generate html with asciidoc, save it the jekyll folder: ,aj
  • list current blogs, check the new blog: ,js
  • use git to publish it: ,gg
    == blog with asciidoc

    I like MD, but ASCIIDOC is my (current) favorite markup. I really need to be
    able to write my blog with asciidoc, then publish the HTML web page — these
    can/should be automated in VIM.

    === here is the code

    ----
    "Asciidoc2Jekyll

    function s:esctitle(str)
      let str = a:str
      let str = tolower(str)
      let str = substitute(str, g:jekyll_title_pattern, '-', 'g')
      let str = substitute(str, '\(--\)\+', '-', 'g')
      let str = substitute(str, '\(^-\|-$\)', '', 'g')
      return str
    endfunction

    "(02/20/2013) publish a asciidoc-generated html blog
    function! Asciidoc2Jekyll(leveloffset, title)
        let os=a:leveloffset
        let title=a:title

        if title == ''
          let title = input("Post title: ")
        endif

        if title != ''
            let file_name = strftime("%Y-%m-%d-") .
               \s:esctitle(title) .
               \"." . "html"

            "exe "tabedit " . g:jekyll_path . "/_posts/" . file_name
            let full_name = g:jekyll_path . "/_posts/" . file_name

            let g:AsciidocCmd = ":0,\$w !asciidoc
                \-a numbered -a toc2
                \-a toclevels=4
                \-a iconsdir=/home/ping/bin/asciidoc-8.6.8/images/icons
                \-a icons -a data-uri -a showcomments
                \-o " . full_name . " " . "
                \-a leveloffset=" . os . "@" . " " . "
                \-b bootstrap-docs - "

            echo "the follow CLI will be executed\n" g:AsciidocCmd

            let isSure=input("are you sure?(y/n)",'y')
            if isSure == 'y'
                exec g:AsciidocCmd
            else
                return g:AsciidocCmd
            endif
        endif
    endf

    command! -nargs=* A2J :call Asciidoc2Jekyll(<f-args>)
    nn <expr> ,aj ':' . Asciidoc2Jekyll(-1, "new_post") . repeat("\<left>", 24)

    "git

    "todo: need to return the cmd but "not" to excute
    function! MyGit(commitmsg)
        let commitmsg=a:commitmsg
        let GitCmd=":!
            \git add -A .;
            \git commit -m \"" .
            \commitmsg . "\";" . "
            \git push origin master"
            "\repeat("\<left>", 30)
        return ":" . GitCmd
    endf
    command! -nargs=* MyGit exec MyGit(<q-args>)

    "command! -nargs=* MyGit  call MyGit(<q-args>)

    "this works, but too ugly
    "nn ,gg :!git add -A .;git commit -m "msg: ";git push origin master"
    "            \<left><left><left><left><left><left><left>
    "            \<left><left><left><left><left><left><left>
    "            \<left><left><left><left><left><left><left>
    "            \<left><left><left><left><left>
    "this is much better
    nn <expr> ,gg ':' . MyGit("new post:") . repeat("\<left>", 24)

    ----

    === how to use it

    * generate html with asciidoc, save it the jekyll folder: `,aj`
    * list current blogs, check the new blog: `,js`
    * use git to publish it: `,gg`


blog comments powered by Disqus

Published

21 February 2013

Category

tech

Tags