Zenn

One org file as one book

New book is composed as one org file, using ox-zenn.

Export function

(defun org-zenn-export-buffer-to-book (&optional org-dir)
    "Runs subtree export to each level 1 headings. Respects `#+BOOK_DIR'."
    (interactive)
    (org-babel-tangle)

    ;; export all
    (let* ((default-dir default-directory)
           (pub-dir (car (cdr (car (org-collect-keywords '("BOOK_DIR")))))))
        ;; cd into the target directory
        (when pub-dir (cd pub-dir))
        ;; export all
        (unwind-protect
                (org-map-entries
                 (lambda ()
                     (let* ((is-draft (org-entry-get nil "DRAFT")))
                         (unless is-draft
                             (org-zenn-export-to-markdown nil t))))
                 "LEVEL=1")
            ;; be sure to come back to the default directory
            (when pub-dir (cd default-dir)))))

File structure

The repository structure:

/zenn
├── books/
├── img/
└── org/

The org book structure is shown in ./org/kyopro-bonsai-hs.org.