0

Why is my org mode publish derived backend not reconized in the code snipped below?

 (if (org-export-derived-backend-p backend 'jekyllHtmlPost)

This is my complete init.el

;;; package --- Summary

;;; Commentary:

;;; Code:

(require 'cl-lib)
;; -*- coding: utf-8; lexical-binding: t; -*-


(require 'ox-org)
(require 'ox-publish)


(message "Arquivo init.el carregado com sucesso!")

;;https://pank.eu/blog/blog-setup.html
(defun configure_jekyll_front_matter (output backend info)
  "Configure Jekyll front matter after jekyllHtmlPost publish    backend.OUTPUT BACKEND INFO."

  (if (org-export-derived-backend-p backend 'jekyllHtmlPost)
      ;;this is never executed
      (message "jekyllHtml backend")
    (message "not jekyllHtml"))

;  (setq frontMatter (format "---\ntitle:%s\nauthor:%s\nlayout:%s    \nexcerpt:%s\ndate:\n---\n"
;                         (org-export-data (or (plist-get info :title)     "?Title?") info)
;                         (org-export-data (or (plist-get info :author)     "?author?") info)
;                         (org-export-data (or (plist-get info     :jekyll_layout) "?jekyll layout here?") info)
;                         (org-export-data (or (plist-get info     :jekyll_excerpt) "?post excerpt here? ") info)
;                       ))

;(concat frontMatter output)

)

(add-to-list 'org-export-filter-final-output-functions
             'configure_jekyll_front_matter)


;;https://github.com/theodorewiles/org-mind-map/issues/22
(org-export-define-derived-backend 'jekyllHtmlPost 'html
   :menu-entry
   '(?j "Jekyll HTML post"
        ((?J "As Body HTML buffer" org-html-export-as-html)
     (?j "As Body HTML file" org-html-export-to-html)
     (?o "As Body HTML file and open"
         (lambda (a s v b)
           (if a (org-html-export-to-html t s v b)
                 (org-open-file (org-html-export-to-html nil s v b)))))))
   :options-alist
   '((:with-toc nil nil nil)
     (:creator nil nil nil)
     (:html-doctype "HTML_DOCTYPE" nil fzl-jekyll-org-html-doctype))) ;;     Never include HTML's toc)

(defun fzl-jekyll-org-html-doctype (info)
"Return correct html doctype tag from org-html-doctype-alist,
or the literal value of :html-doctype from INFO if :html-doctype
is not found in the alist.
INFO is a plist used as a communication channel."
   (message "<><><><><><><><><><<>< (defun fzl-jekyll-org-html-doctype         (info)...")
)

;;; init.el ends here

My Elisp is hard :(

Is the answer on "How to do backend-dependent actions in org-mode export" not a suitable aproach in my case?

2

configure_jekyll_front_matter gets 'html as argument BACKEND and not 'jekyllHtmlPost because you use the export functions of the html backend in the :menu-entry of the derived backend.

You must replace the export functions org-html-export-as-html, ... in your derived backend with your own versions org-jekyllHtmlPost-export-as-html, ... .

You find all the needed export functions in the :menu-entry definition of org-export-define-derived-backend.

Copy-paste these export functions from ox-html.el and change for those new export functions the following details:

  • the name, e.g. from org-html-export-as-html to org-jekyllHtmlPost-export-as-html
  • the backend argument of the general export functions (like org-export-to-file) from 'html to 'jekyllHtmlPost

I demonstrate that here on org-html-export-as-html as an example. The copy-pasted and modified code for org-html-export-as-html follows. Thereby, I cut the super-long doc string of org-html-export-as-html short.

(defun org-jekyllHtmlPost-export-as-html
  (&optional async subtreep visible-only body-only ext-plist)
  "Just like `org-html-export-as-html' but use 'jekyllHtmlPost as backend."
  (interactive)
  (org-export-to-buffer 'jekyllHtmlPost "*Org HTML Export*"
    async subtreep visible-only body-only ext-plist
    (lambda () (set-auto-mode t))))
  • Thank you Tobias, it worked like charm :)) – wagnermarques Jul 20 at 19:12
  • @Tobias: I believe you forgot to rename the function, so I edited the answer: please check. – NickD Jul 21 at 23:55
  • @NickD Thanks, no idea how that could slip through. – Tobias Jul 22 at 7:06
  • Hi NickD, I could not figure out why to change 'html to 'jekyllHtmlPost simbol is returning -> Debugger entered--Lisp error: (wrong-type-argument sequencep t) – wagnermarques Jul 22 at 21:27
0

This is a try, its not the final solution yet... As soon as I can I will try it again...

The code below writes jekyll html post with front matter, but are still use html front end.

    ;;; package --- Summary

;;; Commentary:

;;; Code:

;;Entering the Debugger on an Error
;;https://ftp.gnu.org/old-gnu/Manuals/elisp-manual-21-2.8/html_node/elisp_225.html
(setq debug-on-error t)

(find-file "/home/wagner/temp.org")

(require 'cl-lib)
;; -*- coding: utf-8; lexical-binding: t; -*-

(require 'ox-org)
(require 'ox-publish)

(message "Arquivo init.el carregado com sucesso!")

;;https://pank.eu/blog/blog-setup.html
(defun configure_jekyll_front_matter (output backend info)
  "Configure Jekyll front matter after jekyllHtmlPost publish backend.  OUTPUT BACKEND INFO."

  (if (org-export-derived-backend-p backend 'jekyllHtmlPost)
      (message (concat "jekyllHtmlPost backend was issued..." 'jekyllHtmlPost))
      (let ((frontMatter (format "---\ntitle: %s\nauthor: %s\nlayout: %s\ndate: %s\n---\n"
                                (org-export-data (or (plist-get info :title) "?Title?") info)
                                (org-export-data (or (plist-get info :author) "?author?") info)
                                (org-export-data (or (plist-get info :jekyl_layout) "home") info) ;;fixme: provide :jekyll_layout org file
                                (org-export-data (or (plist-get info :date) (format-time-string "%Y-%m-%d")) info)
                                )))
        (concat frontMatter output))
  );if
)

(add-to-list 'org-export-filter-final-output-functions
             'configure_jekyll_front_matter)



;;https://github.com/theodorewiles/org-mind-map/issues/22
(org-export-define-derived-backend 'jekyllHtmlPost 'html
   :menu-entry
   '(?j "Jekyll HTML post"
        ((?j "As Body HTML file" org-jekyllHtml-export-to-html)
     (?o "As Body HTML file and open"
         (lambda (a s v b)
           (if a (org-jekyllHtml-export-to-html t s v b)
                 (org-open-file (org-jekyllHtml-export-to-html nil s v b)))))))
   :options-alist
   '((:body-only t t t) ;;wants only body
     (:creator "CREATOR" nil org-html-creator-string)))


(defun org-jekyllHtml-export-to-html
  (&optional async subtreep visible-only body-only ext-plist)
  (interactive)
  (let* ((body-only "t")
         (extension ".md")
     (file (org-export-output-file-name extension subtreep))
         (file-renamed-as-a-jekyll-post (concat (concat (format-time-string "%Y-%m-%d") "-") file))
         (jekyll-posts-dir "/home/wagner/wagnerdocri@gmail.com3/envs/env-dev/sources/Fedora-Dockerfiles/jekyll/jekyll-websites/planosenotasdeaulas/_posts/")
     (org-export-coding-system org-html-coding-system))

    (org-export-to-file 'html file async subtreep visible-only body-only ext-plist)
    (copy-file file
               (concat jekyll-posts-dir file-renamed-as-a-jekyll-post ))
    );let
  );;defun


;;; init.el ends here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.