Skip to content

Commit

Permalink
feat: Add defcustom org-hugo-section-frag-property
Browse files Browse the repository at this point in the history
This allows users to change the special property
`EXPORT_HUGO_SECTION*` to a string of their choice
e.g. `EXPORT_HUGO_SECTION_FRAG`.

Fixes #615.
  • Loading branch information
kaushalmodi committed Apr 7, 2022
1 parent b1f014a commit b64636b
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions ox-hugo.el
Expand Up @@ -245,6 +245,12 @@ directory where all Hugo posts should go by default."
:type 'directory)
;;;###autoload (put 'org-hugo-section 'safe-local-variable 'stringp)

(defcustom org-hugo-section-frag-property "EXPORT_HUGO_SECTION*"
"Name of the property for Hugo section fragments."
:group 'org-export-hugo
:type 'string)
;;;###autoload (put 'org-hugo-section-frag-property 'safe-local-variable 'stringp)

(defcustom org-hugo-front-matter-format "toml"
"Front-matter format.
This variable can be set to either \"toml\" or \"yaml\"."
Expand Down Expand Up @@ -1563,9 +1569,11 @@ Search is case-insensitive."
"Return the Hugo section path.
This is the path relative to the Hugo \"content\" directory.
If the EXPORT_HUGO_SECTION* keyword is set in the current or a
parent subtree, return the concatenation of the \"HUGO_SECTION\"
and the concatenated \"EXPORT_HUGO_SECTION*\" values as a path.
If the property name from `org-hugo-section-frag-property'
is set in the current or a parent subtree, return the
concatenation of the \"HUGO_SECTION\" keyword and the
concatenated values of `org-hugo-section-frag-property'
property as a path.
Else, return the \"HUGO_SECTION\" path.
Expand All @@ -1574,7 +1582,7 @@ The function always returns a string.
INFO is a plist used as a communication channel."
(let* ((hugo-section-prop (org-entry-get nil "EXPORT_HUGO_SECTION" :inherit))
(hugo-section-kwd (plist-get info :hugo-section))
(hugo-section-frag-prop (org-entry-get nil "EXPORT_HUGO_SECTION*" :inherit))
(hugo-section-frag-prop (org-entry-get nil org-hugo-section-frag-property :inherit))
(section-path-1 (or hugo-section-prop ;EXPORT_HUGO_SECTION gets higher precedence
hugo-section-kwd)) ;This is mainly to support per-file flow
section-path)
Expand All @@ -1587,7 +1595,7 @@ INFO is a plist used as a communication channel."
(when (org-string-nw-p hugo-section-frag-prop)
(setq section-path-1
(concat (file-name-as-directory section-path-1) ;Add trailing slash if absent
(org-hugo--entry-get-concat nil "EXPORT_HUGO_SECTION*" "/"))))
(org-hugo--entry-get-concat nil org-hugo-section-frag-property "/"))))
(setq section-path (file-name-as-directory section-path-1))
;; (message "[ox-hugo section-path DBG] section path: %S" section-path)
section-path))
Expand Down Expand Up @@ -2085,8 +2093,9 @@ Return nil if none of the above are true."
(while (and pheading
(not (org-export-get-node-property :EXPORT_HUGO_SECTION pheading nil)))
;; Add the :EXPORT_HUGO_SECTION* value to the fragment list.
(when (setq fragment (org-export-get-node-property :EXPORT_HUGO_SECTION* pheading nil))
(push fragment fragments))
(let ((section-frag-prop-symbol (intern (format ":%s" org-hugo-section-frag-property))))
(when (setq fragment (org-export-get-node-property section-frag-prop-symbol pheading nil))
(push fragment fragments)))
(setq pheading (org-element-property :parent pheading)))

(when section
Expand Down Expand Up @@ -4260,7 +4269,6 @@ are \"toml\" and \"yaml\"."
"HUGO_ALLOW_SPACES_IN_TAGS"
"HUGO_BLACKFRIDAY"
"HUGO_SECTION"
"HUGO_SECTION*"
"HUGO_BUNDLE"
"HUGO_BASE_DIR"
"HUGO_GOLDMARK"
Expand Down Expand Up @@ -4296,9 +4304,12 @@ are \"toml\" and \"yaml\"."
"HUGO_AUTO_SET_LASTMOD"
"LANGUAGE"
"AUTHOR")))
(mapcar (lambda (str)
(concat "EXPORT_" str))
prop-list)))
(setq prop-list
(mapcar (lambda (str)
(concat "EXPORT_" str))
prop-list))
(push org-hugo-section-frag-property prop-list)
prop-list))

(defun org-hugo--get-valid-subtree ()
"Return the Org element for a valid Hugo post subtree.
Expand Down

0 comments on commit b64636b

Please sign in to comment.