|
|
|
|
@ -127,9 +127,8 @@ directory where all Hugo posts should go by default." |
|
|
|
|
(:hugo-base-dir "HUGO_BASE_DIR" nil nil) |
|
|
|
|
(:hugo-static-images "HUGO_STATIC_IMAGES" nil "images") |
|
|
|
|
(:hugo-code-fence "HUGO_CODE_FENCE" nil "t") |
|
|
|
|
(:hugo-static-images "HUGO_STATIC_IMAGES" "images" nil) |
|
|
|
|
(:hugo-menu-name "HUGO_MENU_NAME" "main" nil) |
|
|
|
|
(:hugo-menu-weight "HUGO_MENU_WEIGHT" 20 nil) |
|
|
|
|
(:hugo-menu-name "HUGO_MENU_NAME" nil "main") |
|
|
|
|
(:hugo-menu-weight "HUGO_MENU_WEIGHT" nil 20) |
|
|
|
|
(:hugo-menu-parent "HUGO_MENU_PARENT" nil nil))) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -425,7 +424,7 @@ INFO is a plist holding export options." |
|
|
|
|
|
|
|
|
|
INFO is a plist used as a communication channel." |
|
|
|
|
;; (message "[hugo front matter DBG] info: %S" (pp info)) |
|
|
|
|
(let* ((fm-format (org-export-data (plist-get info :hugo-front-matter-format) info)) |
|
|
|
|
(let* ((fm-format (plist-get info :hugo-front-matter-format)) |
|
|
|
|
(hugo-date-fmt "%Y-%m-%dT%T%z") |
|
|
|
|
(date-nocolon (or ;; Get the date from the subtree property `EXPORT_DATE' if available |
|
|
|
|
(org-string-nw-p (org-export-data (plist-get info :date) info)) |
|
|
|
|
@ -445,7 +444,14 @@ INFO is a plist used as a communication channel." |
|
|
|
|
(org-export-data (plist-get info :tags) info)))) |
|
|
|
|
(draft (or org-hugo--draft-state |
|
|
|
|
(org-export-data (plist-get info :hugo-draft) info))) |
|
|
|
|
(data `((title . ,(org-export-data (plist-get info :title) info)) |
|
|
|
|
(title (org-export-data (plist-get info :title) info)) |
|
|
|
|
(menu-name (org-string-nw-p (plist-get info :hugo-menu-name))) |
|
|
|
|
(menu-identifier (org-hugo--slug title)) |
|
|
|
|
(menu-parent (plist-get info :hugo-menu-parent)) |
|
|
|
|
(menu-weight (plist-get info :hugo-menu-weight)) |
|
|
|
|
(menu (when menu-name |
|
|
|
|
(cons menu-name `(,menu-identifier ,menu-parent ,menu-weight)))) |
|
|
|
|
(data `((title . ,title) |
|
|
|
|
(date . ,date) |
|
|
|
|
(description . ,(org-export-data (plist-get info :hugo-description) info)) |
|
|
|
|
(tags . ,tags) |
|
|
|
|
@ -460,15 +466,11 @@ INFO is a plist used as a communication channel." |
|
|
|
|
(markup . ,(org-export-data (plist-get info :hugo-markup) info)) |
|
|
|
|
(slug . ,(org-export-data (plist-get info :hugo-slug) info)) |
|
|
|
|
(url . ,(org-export-data (plist-get info :hugo-url) info)) |
|
|
|
|
(menu . ,(org-export-data (plist-get info :hugo-menu-name) info)) |
|
|
|
|
))) |
|
|
|
|
(message "collect-menu output is: %s" (org-hugo--collect-menu-metadata info fm-format)) |
|
|
|
|
;;(message "output of collect-menu is: %s" (car (org-hugo--collect-menu-metadata info))) |
|
|
|
|
;; (message "car of collect-menu: %s" (car (org-hugo--collect-menu-metadata info))) |
|
|
|
|
;; (message "cdr of collect-menu: %s" (cdr (org-hugo--collect-menu-metadata info))) |
|
|
|
|
(org-hugo--gen-front-matter data fm-format info))) |
|
|
|
|
|
|
|
|
|
(defun org-hugo--gen-front-matter (data format info) |
|
|
|
|
(menu . ,menu)))) |
|
|
|
|
;; (message "[get fm menu DBG] %S" menu) |
|
|
|
|
(org-hugo--gen-front-matter data fm-format))) |
|
|
|
|
|
|
|
|
|
(defun org-hugo--gen-front-matter (data format) |
|
|
|
|
"Generate the Hugo post front matter, and return that string. |
|
|
|
|
|
|
|
|
|
DATA is an alist of the form \((KEY1 . VAL1) (KEY2 . VAL2) .. \), |
|
|
|
|
@ -476,7 +478,7 @@ where KEY is a symbol and VAL is a string. |
|
|
|
|
|
|
|
|
|
Generate the front matter in the specified FORMAT. Valid values |
|
|
|
|
are \"toml\" and \"yaml\"." |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(let ((sep (cond ((string= format "toml") "+++\n") |
|
|
|
|
((string= format "yaml") "---\n") |
|
|
|
|
(t ""))) |
|
|
|
|
@ -488,9 +490,10 @@ are \"toml\" and \"yaml\"." |
|
|
|
|
(dolist (pair data) |
|
|
|
|
(let ((key (symbol-name (car pair))) |
|
|
|
|
(value (cdr pair))) |
|
|
|
|
;; (message "[hugo fm key value DBG] %S %S" key value) |
|
|
|
|
(unless (or (null value) |
|
|
|
|
(string= "" value) |
|
|
|
|
(string= "menu" key)) |
|
|
|
|
(and (stringp value) |
|
|
|
|
(string= "" value))) |
|
|
|
|
;; In TOML/YAML, the value portion needs to be wrapped in double quotes |
|
|
|
|
;; TOML example: |
|
|
|
|
;; title = "My Post" |
|
|
|
|
@ -516,41 +519,15 @@ are \"toml\" and \"yaml\"." |
|
|
|
|
(string= key "expirydate") |
|
|
|
|
(string= key "draft")) |
|
|
|
|
value) |
|
|
|
|
((string= key "menu") |
|
|
|
|
(message "dbg: %S" value) |
|
|
|
|
(message "Need to translate value to menu fm in yaml/toml here") |
|
|
|
|
"") |
|
|
|
|
(t |
|
|
|
|
(org-hugo--wrap-string-in-quotes value))))))))) |
|
|
|
|
(concat sep front-matter (if (alist-get "menu" data) (org-hugo--collect-menu-metadata info format) (org-hugo--collect-menu-metadata info format) ) sep))) |
|
|
|
|
|
|
|
|
|
(defun org-hugo--collect-menu-metadata (info format) |
|
|
|
|
"collect all the menu-related metadata and return a nested plist of the values |
|
|
|
|
to be used by toml and yaml frontmatter creators." |
|
|
|
|
;;(message "info: %s" info) |
|
|
|
|
(let* ((menu-atts '(:hugo-menu-parent "parent" :hugo-menu-weight "weight")) |
|
|
|
|
(menu-name (plist-get info :hugo-menu-name)) |
|
|
|
|
(menu-identifier (plist-get info :title)) |
|
|
|
|
(menu-weight (plist-get info :hugo-menu-weight)) |
|
|
|
|
(menu-parent (plist-get info :hugo-menu-parent)) |
|
|
|
|
;; (atts-plist (cl-loop for att in (plist-get-keys menu-atts) |
|
|
|
|
;; collect (plist-get menu-atts att) |
|
|
|
|
;; collect (plist-get info att))) |
|
|
|
|
;;(menu-plist (plist-put '() menu-name `("parent" ,menu-parent "weight" ,menu-weight))) |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(if (string= format "yaml") |
|
|
|
|
(let ((indent " ")) |
|
|
|
|
(format "\nmenu:\n %s:\n %s: %s\n %s: %s\n %s: %s\n" |
|
|
|
|
menu-name |
|
|
|
|
"identifier" (plist-get info :title) |
|
|
|
|
"parent" (plist-get info :hugo-menu-parent ) |
|
|
|
|
"weight" (plist-get info :hugo-menu-weight))) |
|
|
|
|
(format "[[menu.%s]]\n %s = %s\n %s = %s\n% s = %s\n" |
|
|
|
|
menu-name |
|
|
|
|
"parent" (plist-get info :hugo-menu-parent ) |
|
|
|
|
"identifier" (plist-get info :title) |
|
|
|
|
"weight" (plist-get info :hugo-menu-weight)) |
|
|
|
|
))) |
|
|
|
|
(concat sep front-matter sep))) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; Interactive functions |
|
|
|
|
|
|
|
|
|
;;;###autoload |
|
|
|
|
|