From 18d252eddb5803e4598eec1851b0dd3263e7ad94 Mon Sep 17 00:00:00 2001 From: Kaushal Modi Date: Fri, 30 Jun 2017 19:18:12 -0400 Subject: [PATCH] Add checks that required HUGO properties are defined Also create pub-dir if it does not exist. Add a minimal test case. --- ox-hugo.el | 14 ++++++++++---- tests/org/small1/small1.org | 9 +++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 tests/org/small1/small1.org diff --git a/ox-hugo.el b/ox-hugo.el index 1379703..a0a150e 100644 --- a/ox-hugo.el +++ b/ox-hugo.el @@ -401,7 +401,6 @@ contents of hidden elements. Return output file's name." (interactive) - ;; steals some plist reading code ;; from =org-export-as= ;; allows us to extract destination file info from @@ -411,9 +410,16 @@ Return output file's name." 'hugo subtreep visible-only) (org-export--get-buffer-attributes) (org-export-get-environment 'hugo subtreep))) - (pub-dir (concat (file-name-as-directory (plist-get info :hugo-export-dir) ) - (file-name-as-directory "content") - (file-name-as-directory (plist-get info :hugo-section)))) + (export-dir-path (if (null (plist-get info :hugo-export-dir)) + (user-error "It is mandatory to set the HUGO_EXPORT_DIR property") + (file-name-as-directory (plist-get info :hugo-export-dir)))) + (content-dir "content/") + (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)))) + (pub-dir (let ((dir (concat export-dir-path content-dir section-dir))) + (make-directory dir :parents) ;Create the directory if it does not exist + dir)) (outfile (org-export-output-file-name ".md" subtreep pub-dir))) (org-export-to-file 'hugo outfile async subtreep visible-only))) diff --git a/tests/org/small1/small1.org b/tests/org/small1/small1.org new file mode 100644 index 0000000..d4c9ae7 --- /dev/null +++ b/tests/org/small1/small1.org @@ -0,0 +1,9 @@ +#+TITLE: My Blog +#+HUGO_EXPORT_DIR: ~/temp/small1/ +#+HUGO_SECTION: posts + +# 1. Load `ox-hugo' +# 2. M-x org-hugo-walk-headlines + +* Post 1 +Something