Skip to content

Commit

Permalink
org-hugo--heading-get-slug: Parse the #+hugo_section keyword too
Browse files Browse the repository at this point in the history
Also add a new optional arg `inherit-export-file-name`.
  • Loading branch information
kaushalmodi committed Mar 17, 2022
1 parent 6d671fd commit 8875e1a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
17 changes: 12 additions & 5 deletions ox-hugo.el
Expand Up @@ -1890,7 +1890,7 @@ This function will never return nil."
"")))
(substring (md5 title) 0 hash-len)))

(defun org-hugo--heading-get-slug (heading _info)
(defun org-hugo--heading-get-slug (heading info &optional inherit-export-file-name)
"Return the slug string derived from an Org HEADING element.
1. If HEADING has `:EXPORT_FILE_NAME' and `:EXPORT_HUGO_SLUG'
Expand All @@ -1908,11 +1908,16 @@ This function will never return nil."
is neither \"index\" nor \"_index\", use that to derive the
slug.
The `:EXPORT_HUGO_SECTION' property is prepended to all of the
above options.
If INHERIT-EXPORT-FILE-NAME is non-nil, allow inheriting the
`:EXPORT_FILE_NAME' property from a parent subtree.
The `:EXPORT_HUGO_SECTION' property or `#+hugo_section' keyword
value is prepended to all of the above options.
INFO is a plist used as a communication channel.
Return nil if none of the above are true."
(let ((file (org-string-nw-p (org-export-get-node-property :EXPORT_FILE_NAME heading)))
(let ((file (org-string-nw-p (org-export-get-node-property :EXPORT_FILE_NAME heading inherit-export-file-name)))
hugo-slug bundle slug)
;; (message "[org-hugo--heading-get-slug DBG] EXPORT_FILE_NAME: %S" file)
(when file
Expand Down Expand Up @@ -1950,7 +1955,9 @@ Return nil if none of the above are true."
(when slug
(let ((pheading heading)
section fragment fragments)
(setq section (org-string-nw-p (org-export-get-node-property :EXPORT_HUGO_SECTION heading :inherited)))
(setq section (org-string-nw-p
(or (org-export-get-node-property :EXPORT_HUGO_SECTION heading :inherited)
(plist-get info :hugo-section))))

;; Iterate over all parents of heading, and collect section
;; path fragments.
Expand Down
2 changes: 1 addition & 1 deletion test/ert/org-test-lib.el
Expand Up @@ -56,7 +56,7 @@ variable, and communication channel under `info'."
(let* ((tree (org-element-parse-buffer))
(info (org-combine-plists
(org-export--get-export-attributes)
(org-export-get-environment))))
(org-export-get-environment 'hugo))))
(org-export--prune-tree tree info)
(org-export--remove-uninterpreted-data tree info)
(let ((info (org-combine-plists
Expand Down
15 changes: 15 additions & 0 deletions test/ert/tslug.el
Expand Up @@ -212,6 +212,21 @@
(let ((el (org-element-at-point)))
(org-hugo--heading-get-slug el info))))))

;; Section
(ert-deftest test-slug/section ()

;; Section keyword
(should
(string= "section/file"
(org-test-with-parsed-data
"#+hugo_section: section
* Some Heading<point>
:PROPERTIES:
:EXPORT_FILE_NAME: file
:END:"
(let ((el (org-element-at-point)))
(org-hugo--heading-get-slug el info))))))

;; Section fragments
(ert-deftest test-slug/section-fragments ()

Expand Down

0 comments on commit 8875e1a

Please sign in to comment.