Skip to content

Commit

Permalink
Add test and docs for the new `org-hugo-base-dir' variable
Browse files Browse the repository at this point in the history
Ref: #401
  • Loading branch information
kaushalmodi committed May 18, 2021
1 parent db6adc9 commit 805f18b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 19 deletions.
32 changes: 18 additions & 14 deletions doc/ox-hugo-manual.org
Original file line number Diff line number Diff line change
Expand Up @@ -427,24 +427,28 @@ Spacemacs users can use =ox-hugo= by setting the variable
:CUSTOM_ID: before-you-export
:END:
Before you export check that these properties are set as you need:
- HUGO_SECTION :: The default Hugo section name for all the posts. See
[[https://gohugo.io/content-management/sections/][here]] for more information on Hugo sections. It is
common for this property to be set to =posts= or
=blog=. The default value is set using
=org-hugo-default-section-directory=. See
{{{doc(hugo-section,,Hugo Section)}}} for details.
- HUGO_BASE_DIR :: Root directory of the source for the Hugo site. If
this is set to =~/hugo/=, the exported Markdown
files will be saved to
=~/hugo/content/<HUGO_SECTION>/=
directory[fn:section_more]. By default, the
Markdown files reside in a hierarchy under the
=content/= directory in the site root directory
([[https://gohugo.io/content-management/organization/][ref]]). If you try to export without setting this
property, you will get this error:
this is set to =~/hugo/=, the exported Markdown files will be saved
to =~/hugo/content/<HUGO_SECTION>/= directory[fn:section_more]. By
default, the Markdown files reside in a hierarchy under the
=content/= directory in the site root directory ([[https://gohugo.io/content-management/organization/][ref]]).

If you try to export without setting this property, you will get
this error:
#+begin_example
user-error: It is mandatory to set the HUGO_BASE_DIR property
or the `org-hugo-base-dir' local variable
#+end_example
This property can be set by one of two ways:
1. Setting the ~#+hugo_base_dir:~ keyword in the Org file.
2. Setting the ~org-hugo-base-dir~ variable in a ~.dir-locals.el~ or
File Local Variables.

- HUGO_SECTION :: The default Hugo section name for all the posts.
See [[https://gohugo.io/content-management/sections/][here]] for more information on Hugo sections. It is common for
this property to be set to =posts= or =blog=. The default value is
set using =org-hugo-default-section-directory=. See
{{{doc(hugo-section,,Hugo Section)}}} for details.

*Important*: If you choose to export an Org subtree as a post, you
need to set the =EXPORT_FILE_NAME= subtree property. That property is
Expand Down
11 changes: 8 additions & 3 deletions ox-hugo.el
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 +400,14 @@ Examples:

(define-obsolete-variable-alias 'org-hugo-default-section-directory 'org-hugo-section "Oct 31, 2018")

(defvar-local org-hugo-base-dir nil
(defcustom org-hugo-base-dir nil
"Base directory for Hugo.
Set either this value, or the HUGO_BASE_DIR global property for export.")
Set either this value, or the HUGO_BASE_DIR global property for
export."
:group 'org-export-hugo
:type 'directory)
;;;###autoload (put 'org-hugo-base-dir 'safe-local-variable 'stringp)

(defcustom org-hugo-section "posts"
"Default section for Hugo posts.
Expand Down Expand Up @@ -1281,7 +1286,7 @@ The publication directory is created if it does not exist.
INFO is a plist used as a communication channel."
(let* ((base-dir (if (plist-get info :hugo-base-dir)
(file-name-as-directory (plist-get info :hugo-base-dir))
(user-error "It is mandatory to set the HUGO_BASE_DIR property or the org-hugo-base-dir local variable")))
(user-error "It is mandatory to set the HUGO_BASE_DIR property or the `org-hugo-base-dir' local variable")))
(content-dir "content/")
(section-path (org-hugo--get-section-path info))
(bundle-dir (let ((bundle-path (or ;Hugo bundle set in the post subtree gets higher precedence
Expand Down
1 change: 1 addition & 0 deletions test/site/content-org/dir-locals/.dir-locals.el
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
(fill-column . 70)
(sentence-end-double-space . t)))
(org-mode . ((mode . auto-fill)
(org-hugo-base-dir . "../../.")
(org-hugo-section . "dir-locals-test")
(org-hugo-front-matter-format . "yaml")
(org-hugo-footer . "\n\nThis text is auto inserted at the end of the exported Markdown.")
Expand Down
3 changes: 1 addition & 2 deletions test/site/content-org/dir-locals/dir-locals-test.org
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#+hugo_base_dir: ../../.

#+title: .dir-locals.el test
#+date: <2018-10-31 Wed>

Expand All @@ -16,6 +14,7 @@ Test setting of few Org Hugo variables via =.dir-locals.el=.
|----------------------------------------+-------------------------------------------------------------------------|
| Variable | Value |
|----------------------------------------+-------------------------------------------------------------------------|
| =org-hugo-base-dir= | ="../../."= |
| =org-hugo-section= | ="dir-locals-test"= |
| =org-hugo-front-matter-format= | ="yaml"= |
| =org-hugo-footer= | ="\n\nThis text is auto inserted at the end of the exported Markdown."= |
Expand Down
1 change: 1 addition & 0 deletions test/site/content/dir-locals-test/dir-locals-test.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ creator: "Dummy creator string"

| Variable | Value |
|----------------------------------------|-------------------------------------------------------------------------|
| `org-hugo-base-dir` | `"../../."` |
| `org-hugo-section` | `"dir-locals-test"` |
| `org-hugo-front-matter-format` | `"yaml"` |
| `org-hugo-footer` | `"\n\nThis text is auto inserted at the end of the exported Markdown."` |
Expand Down

0 comments on commit 805f18b

Please sign in to comment.