Skip to content

Commit

Permalink
Add full support for #+hugo:
Browse files Browse the repository at this point in the history
Just as ox-md.el supports `#+md:` and ox-html.el supports `#+html:`.
  • Loading branch information
kaushalmodi committed Dec 15, 2021
1 parent 8abbf78 commit 36d87a2
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 24 deletions.
43 changes: 23 additions & 20 deletions ox-hugo.el
Expand Up @@ -2017,11 +2017,14 @@ channel."
(let ((kwd (org-element-property :key keyword))
(value (org-element-property :value keyword)))
(cond
((and (equal "HUGO" kwd) ;Hugo summary splitting
(stringp value)
(string-match-p "\\`\\s-*more\\s-*\\'" value))
;; https://gohugo.io/content-management/summaries#user-defined-manual-summary-splitting
"<!--more-->")
((and (equal "HUGO" kwd))
(if (and (stringp value) ;Hugo summary splitting
(string-match-p "\\`\\s-*more\\s-*\\'" value))
(progn
;; https://gohugo.io/content-management/summaries#user-defined-manual-summary-splitting
"<!--more-->")
(progn
value)))
((and (equal "TOC" kwd)
(string-match-p "\\<headlines\\>" value))
(let* ((depth (and (string-match "\\<[0-9]+\\>" value)
Expand Down Expand Up @@ -4031,7 +4034,7 @@ links."
(org-export-get-environment 'hugo)))
(local-variables (buffer-local-variables))
(bound-variables (org-export--list-bound-variables))
vars)
vars)
(with-current-buffer buffer
(let ((inhibit-modification-hooks t)
(org-mode-hook nil)
Expand All @@ -4042,20 +4045,20 @@ links."
;; through BIND keywords.
(dolist (entry local-variables vars)
(when (consp entry)
(let ((var (car entry))
(val (cdr entry)))
(and (not (memq var org-export-ignored-local-variables))
(or (memq var
'(default-directory
buffer-file-name
buffer-file-coding-system))
(assq var bound-variables)
(string-match "^\\(org-\\|orgtbl-\\)"
(symbol-name var)))
;; Skip unreadable values, as they cannot be
;; sent to external process.
(or (not val) (ignore-errors (read (format "%S" val))))
(push (set (make-local-variable var) val) vars)))))
(let ((var (car entry))
(val (cdr entry)))
(and (not (memq var org-export-ignored-local-variables))
(or (memq var
'(default-directory
buffer-file-name
buffer-file-coding-system))
(assq var bound-variables)
(string-match "^\\(org-\\|orgtbl-\\)"
(symbol-name var)))
;; Skip unreadable values, as they cannot be
;; sent to external process.
(or (not val) (ignore-errors (read (format "%S" val))))
(push (set (make-local-variable var) val) vars)))))

;; Process all link elements in the AST.
(org-element-map ast 'link
Expand Down
28 changes: 25 additions & 3 deletions test/site/content-org/all-posts.org
Expand Up @@ -2300,16 +2300,17 @@ If the =EXPORT_HUGO_OUTPUTS= property is left empty/unset, =ox-hugo=
will not set the =outputs= variable in the front-matter at all. So
only the HTML output will be created (default).
* Post body :body:
** Summary Splitter :summary_splitter:more:
*** Summary Splitter
** ~#+hugo~ keyword :keyword:hugo:
*** Summary Splitter :summary_splitter:more:
**** Summary Splitter
:PROPERTIES:
:EXPORT_FILE_NAME: summary-splitter
:EXPORT_DATE: 2017-07-21
:END:
Here is the summary.
#+hugo: more
Here is text after the [[https://gohugo.io/content-management/summaries#user-defined-manual-summary-splitting][summary splitter]].
*** COMMENT Summary Splitter at EOF :eof:
**** COMMENT Summary Splitter at EOF :eof:
:PROPERTIES:
:EXPORT_FILE_NAME: summary-splitter-at-eof
:END:
Expand All @@ -2323,6 +2324,27 @@ Summary splitter at the end of post

Here more summary.
#+hugo: more
*** Hugo keyword
:PROPERTIES:
:EXPORT_FILE_NAME: hugo-keyword
:END:
#+begin_description
Stuff followed the ~#+hugo:~ exports as-is except when it is "more"
#+end_description

As the content following ~#+hugo:~ exports as-is to the Markdown, that
content should be what Hugo can parse (i.e. Markdown, shortcodes,
etc).

This Org snippet:

#+begin_src org
,#+hugo: This `relref` links to [this same page]({​{< relref "hugo-keyword" >}}).
#+end_src

renders as below:

#+hugo: This `relref` links to [this same page]({{< relref "hugo-keyword" >}}).
** Dealing with underscores
:PROPERTIES:
:EXPORT_FILE_NAME: dealing-with-underscores
Expand Down
20 changes: 20 additions & 0 deletions test/site/content/posts/hugo-keyword.md
@@ -0,0 +1,20 @@
+++
title = "Hugo keyword"
description = "Stuff followed the `#+hugo:` exports as-is except when it is \"more\""
tags = ["body", "keyword", "hugo"]
draft = false
+++

As the content following `#+hugo:` exports as-is to the Markdown, that
content should be what Hugo can parse (i.e. Markdown, shortcodes,
etc).

This Org snippet:

```org
#+hugo: This `relref` links to [this same page]({​{< relref "hugo-keyword" >}}).
```

renders as below:

This `relref` links to [this same page]({{< relref "hugo-keyword" >}}).
2 changes: 1 addition & 1 deletion test/site/content/posts/summary-splitter.md
@@ -1,7 +1,7 @@
+++
title = "Summary Splitter"
date = 2017-07-21
tags = ["body", "summary-splitter", "more"]
tags = ["body", "keyword", "hugo", "summary-splitter", "more"]
draft = false
+++

Expand Down

0 comments on commit 36d87a2

Please sign in to comment.