From 3ed95b330d1b9ae4577db43f41d39322304865b5 Mon Sep 17 00:00:00 2001 From: Kaushal Modi Date: Thu, 18 Jan 2018 17:52:24 -0500 Subject: [PATCH] Support the case where the bundle name is set in the post subtree --- ox-hugo.el | 24 +++++++++++++++---- test/site/content-org/all-posts.org | 6 +++++ .../content/bundles/page-bundle-b/index.md | 7 ++++++ 3 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 test/site/content/bundles/page-bundle-b/index.md diff --git a/ox-hugo.el b/ox-hugo.el index a4e8ed0..be9d63a 100644 --- a/ox-hugo.el +++ b/ox-hugo.el @@ -90,6 +90,16 @@ It holds the value returned by "Variable to count of number of subtrees getting exported. This variable is used when exporting all subtrees in a file.") +(defvar org-hugo--bundle nil + "Variable to store the current valid Hugo subtree bundle name. +If the EXPORT_HUGO_BUNDLE property is set in the same subtree as +the post subtree, it somehow cannot be parsed from +`org-hugo-export-to-md'. But that property can be accessed +within `org-hugo-export-wim-to-md' regardless. This variable +helps set the bundle path correctly for such cases (where +EXPORT_HUGO_BUNDLE and EXPORT_FILE_NAME are set in the same +subtree).") + (defvar org-hugo-allow-export-after-save t "Enable flag for `org-hugo-export-wim-to-md-after-save'. When nil, the above function will not export the Org file to @@ -945,7 +955,7 @@ If hugo is not found, return nil." "Generate a merged RESOURCES alist. All parameters for the same \"src\" are merged together in the -same lisp form. Parameters that are none of \"src\", \"title\" +same Lisp form. Parameters that are none of \"src\", \"title\" or \"name\" are packed into an alist with `car' as \"params\"." ;; (message "[resources IN DBG]: %S" resources) (when resources @@ -1008,8 +1018,7 @@ Examples: \"abc\ndef\" -> \"[\\\"abc\\\", \\\"def\\\"]\" - \(\"abc\" \"def\") -> \"[\\\"abc\\\", \\\"def\\\"]\" -" + \(\"abc\" \"def\") -> \"[\\\"abc\\\", \\\"def\\\"]\"." (when (listp value) ;; Convert value to a string (setq value (mapconcat @@ -1045,8 +1054,10 @@ INFO is a plist used as a communication channel." (section-dir (if (null (plist-get info :hugo-section)) (user-error "It is mandatory to set the HUGO_SECTION property") (file-name-as-directory (plist-get info :hugo-section)))) - (bundle-dir (if (plist-get info :hugo-bundle) - (file-name-as-directory (plist-get info :hugo-bundle)) + (bundle-name (or (plist-get info :hugo-bundle) + org-hugo--bundle)) + (bundle-dir (if bundle-name + (file-name-as-directory bundle-name) "")) (pub-dir (let ((dir (concat base-dir content-dir section-dir bundle-dir))) (make-directory dir :parents) ;Create the directory if it does not exist @@ -2677,6 +2688,7 @@ Return output file's name." (progn ;; Reset the variables that are used only for subtree exports. (setq org-hugo--subtree-coord nil) + (setq org-hugo--bundle nil) (message "[ox-hugo] Exporting `%s' (%s)" title fname)) (message "[ox-hugo] %s was not exported as it is tagged with an exclude tag `%s'" fname matched-exclude-tag)))) @@ -2831,6 +2843,8 @@ approach)." (re-search-forward "^#\\+HUGO_WEIGHT:[[:blank:]]*auto" nil :noerror)))) (setq org-hugo--subtree-coord (org-hugo--get-post-subtree-coordinates subtree))) + ;; Get the current subtree bundle name if any. + (setq org-hugo--bundle (org-entry-get nil "EXPORT_HUGO_BUNDLE" :inherit)) (setq do-export t))))) ;; If not in a valid subtree, check if the Org file is ;; supposed to be exported as a whole, in which case diff --git a/test/site/content-org/all-posts.org b/test/site/content-org/all-posts.org index 22d8e54..0620b91 100644 --- a/test/site/content-org/all-posts.org +++ b/test/site/content-org/all-posts.org @@ -1847,6 +1847,12 @@ the copied location inside the bundle: :EXPORT_FILE_NAME: bar :END: "Bar" page in /Page Bundle A/. +** Page Bundle B +:PROPERTIES: +:EXPORT_FILE_NAME: index +:EXPORT_HUGO_BUNDLE: page-bundle-b +:END: +Index page of /Page Bundle B/. * Footnotes Test :footnote: ** Footnotes 1 :PROPERTIES: diff --git a/test/site/content/bundles/page-bundle-b/index.md b/test/site/content/bundles/page-bundle-b/index.md new file mode 100644 index 0000000..d928e59 --- /dev/null +++ b/test/site/content/bundles/page-bundle-b/index.md @@ -0,0 +1,7 @@ ++++ +title = "Page Bundle B" +tags = ["page-bundles"] +draft = false ++++ + +Index page of _Page Bundle B_.