Edit YAML frontmatter in blog in org-mode designed for Jekyll

I would like to use org-mode emacs to write blog posts for my Jekyll driven blog. Reading Using an org for Blog with Jekyll , what is usually done is that you make your front in the #+BEGIN_HTML

/ block #+END_HTML

, which passes the front subject through untouched.

However, using org-edit-special

( C-c '

) will get you html-mode

in a dedicated edit buffer. Going to yaml-mode

does not work because you cannot go back from special edit mode.

Is there a way to edit this front in yaml-mode

without using things like changing the entire buffer to yaml-mode

and then back to org-mode

?

+3


source to share


2 answers


You can create a custom command where html is linked to yaml-mode.

(defun org-edit-html-export-block-as-yaml ()
  (interactive)
  (let ((org-src-lang-modes '(("html" . yaml))))
    (org-edit-export-block)))

(define-key org-mode-map YOUR-KEY 'org-edit-html-export-block-as-yaml)

      

I tested this (with a development version of Org mode) on



#+begin_html
key: 3
#+end_html

      

and seems to be working fine.

+1


source


This is what I came up with:

Creating a calendar function for yaml:

(defun org-babel-execute:yaml (body params) body)

      



Then I can do what I would like:

#+STARTUP: showall expand
#+options: toc:nil
#+begin_src yaml :exports results :results value html
  ---
  layout: post
  title: test post with yaml source block frontmatter
  gallery:
    path: abc123
    images:
      - blah.png
      - bloo.png
  ---
#+end_src

* hello world

      

And it gives exactly what I want in the markdown file when I export it.

+1


source







All Articles