Skip to content

Commit

Permalink
Support Org #+AUTHOR keyword
Browse files Browse the repository at this point in the history
Also allow disabling author export.

This commit might be a big behavior change for some as now the author
name is auto-exported to the post front matter.

To disable that, simply put "#+AUTHOR:" or "#+OPTIONS: author:nil" at
the top of your Org file.

With this commit, ox-hugo now supports one more implicit ox.el
feature.

Part of solution to #106
  • Loading branch information
kaushalmodi committed Dec 1, 2017
1 parent e86ab6a commit 852ab6c
Show file tree
Hide file tree
Showing 33 changed files with 113 additions and 20 deletions.
10 changes: 10 additions & 0 deletions ox-hugo.el
Original file line number Diff line number Diff line change
Expand Up @@ -1789,6 +1789,15 @@ INFO is a plist used as a communication channel."
;; (message "[hugo front matter DBG] info: %S" (pp info))
(let* ((fm-format (plist-get info :hugo-front-matter-format))
(title (org-entry-get (point) "ITEM")) ;Post title
(author-list (and (plist-get info :with-author)
(let ((author-raw
(org-string-nw-p
(org-export-data (plist-get info :author) info))))
(when author-raw
;; Comma-separated multiple authors
(let ((author-list-1 (org-split-string author-raw ",")))
;; Don't allow spaces around author names.
(mapcar #'org-trim author-list-1))))))
(hugo-date-fmt "%Y-%m-%dT%T%z")
(date-raw (or
;; Get the date from the "CLOSED" property;
Expand Down Expand Up @@ -1935,6 +1944,7 @@ INFO is a plist used as a communication channel."
(data `(;; The order of the elements below will be the order in which the front matter
;; variables will be ordered.
(title . ,(org-hugo--sanitize-title info))
(author . ,author-list)
(description . ,(org-export-data (plist-get info :description) info))
(date . ,date)
(publishDate . ,(org-export-data (plist-get info :hugo-publishdate) info))
Expand Down
46 changes: 37 additions & 9 deletions test/site/content-org/all-posts.org
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#+HUGO_BASE_DIR: ../
#+SEQ_TODO: TODO DRAFT DONE
#+PROPERTY: header-args :eval no

#+MACRO: doc [[https://ox-hugo.scripter.co/doc/$1][$2]]
#+MACRO: oxhugoissue =ox-hugo= Issue #[[https://github.com/kaushalmodi/ox-hugo/issues/$1][$1]]

#+AUTHOR:

* Preparation
:PROPERTIES:
:EXPORT_FILE_NAME: prep
Expand Down Expand Up @@ -2609,53 +2612,76 @@ a_{b} a_{bc} a^{b} a^{bc}
:END:
This post will be exported without =title= in the front-matter because
it is disabled using =:EXPORT_OPTIONS: title:nil=.
* Hugo Aliases :aliases:
** Alias without section portion 1
** Disable exporting author :author:disable:
:PROPERTIES:
:EXPORT_OPTIONS: author:nil
:EXPORT_FILE_NAME: disable-author
:EXPORT_AUTHOR: Foo Bar
:END:
This post will be exported without =author= in the front-matter because
it is disabled using =:EXPORT_OPTIONS: author:nil=.
* Miscellaneous Front Matter :front_matter:
** Hugo Aliases :aliases:
*** Alias without section portion 1
:PROPERTIES:
:EXPORT_FILE_NAME: alias-without-section-1
:EXPORT_HUGO_ALIASES: alias-a
:END:
As the specified alias does not contain the "/" string, it will be
auto-prefixed with the section for the current post.
** New section just for test
*** New section just for test
:PROPERTIES:
:EXPORT_HUGO_SECTION: alias-test
:END:
*** Alias without section portion 2
**** Alias without section portion 2
:PROPERTIES:
:EXPORT_FILE_NAME: alias-without-section-2
:EXPORT_HUGO_ALIASES: alias-b
:END:
As the specified alias does not contain the "/" string, it will be
auto-prefixed with the section for the current post.
** Alias specifying a different section
*** Alias specifying a different section
:PROPERTIES:
:EXPORT_FILE_NAME: alias-different-section
:EXPORT_HUGO_ALIASES: /alias-test/alias-c
:END:
** Alias specifying root section
*** Alias specifying root section
:PROPERTIES:
:EXPORT_FILE_NAME: alias-root-section
:EXPORT_HUGO_ALIASES: /alias-d
:END:
** Multiple aliases without section portion
*** Multiple aliases without section portion
:PROPERTIES:
:EXPORT_FILE_NAME: alias-multiple-without-section
:EXPORT_HUGO_ALIASES: alias-e alias-f
:END:
** Multiple aliases with section portion
*** Multiple aliases with section portion
:PROPERTIES:
:EXPORT_FILE_NAME: alias-multiple-with-section
:EXPORT_HUGO_ALIASES: /alias-test/alias-g /alias-test/alias-h
:END:
** Author :author:
*** Single author
:PROPERTIES:
:EXPORT_FILE_NAME: single-author
:EXPORT_AUTHOR: Foo Bar
:END:
This post has 1 author.
*** Multiple authors
:PROPERTIES:
:EXPORT_FILE_NAME: multiple-authors
:EXPORT_AUTHOR: Foo Bar, Toto Kumar , Zulu ,Ágota Kristóf
:END:
This post has multiple authors. In Org, multiple authors are added
comma-separated.
* Real Examples :real_examples:
:PROPERTIES:
:EXPORT_HUGO_SECTION: real-examples
:END:
** Multifractals in ecology using R :math:equations:
:PROPERTIES:
:EXPORT_FILE_NAME: multifractals-in-ecology-using-r
:EXPORT_HUGO_CUSTOM_FRONT_MATTER: :author Leonardo A. Saravia
:EXPORT_AUTHOR: Leonardo A. Saravia
:EXPORT_HUGO_CUSTOM_FRONT_MATTER+: :source https://github.com/lsaravia/MultifractalsInR/blob/master/Curso3.md
:EXPORT_DATE: 2017-11-28T10:48:00-05:00
:END:
Expand Down Expand Up @@ -2767,6 +2793,8 @@ auto-prefixed with the section for the current post.
** 神经网络基础 :math:equations:not_english:table:latex:latex_environment:
:PROPERTIES:
:EXPORT_FILE_NAME: nn-intro
:EXPORT_AUTHOR: Feng Ruohang
:EXPORT_HUGO_CUSTOM_FRONT_MATTER+: :source https://github.com/Vonng/Math/blob/master/nndl/nn-intro.md
:EXPORT_DATE: 2017-11-29
:END:
- Disclaimer :: This post is from the [[https://github.com/Vonng/Math/blob/master/nndl/nn-intro.md][link]] posted by GitHub user
Expand Down
2 changes: 2 additions & 0 deletions test/site/content-org/auto-set-lastmod.org
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Auto-set lastmod field in the below posts.
#+HUGO_AUTO_SET_LASTMOD: t

#+AUTHOR:

#+FILETAGS: dont_export_during_make_test

* Auto-set Lastmod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#+HUGO_FRONT_MATTER_FORMAT: yaml
#+HUGO_MENU: :menu main :parent posts

#+AUTHOR:

* Menu Meta Data in YAML Front Matter :menu:yaml:
:PROPERTIES:
:EXPORT_FILE_NAME: menu-meta-data-yaml
Expand Down
2 changes: 2 additions & 0 deletions test/site/content-org/deep-nesting.org
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#+HUGO_BASE_DIR: ../

#+AUTHOR:

* Introduction
See https://github.com/kaushalmodi/ox-hugo/issues/81

Expand Down
2 changes: 2 additions & 0 deletions test/site/content-org/hugo-menu-as-keyword.org
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#+SEQ_TODO: TODO DRAFT DONE
#+HUGO_MENU: :menu "auto weight"

#+AUTHOR:

* Post with menu 1 (HUGO_MENU as keyword)
:PROPERTIES:
:EXPORT_FILE_NAME: hugo-menu-as-keyword--post-with-menu-1
Expand Down
2 changes: 2 additions & 0 deletions test/site/content-org/hugo-weight-as-keyword-auto-calc.org
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#+HUGO_WEIGHT: auto
#+HUGO_TAGS: weight

#+AUTHOR:

* Post 1 with auto calculation of weight (HUGO_WEIGHT as keyword)
:PROPERTIES:
:EXPORT_FILE_NAME: post-1-with-auto-calc-of-weight--hugo-weight-as-keyword
Expand Down
2 changes: 2 additions & 0 deletions test/site/content-org/images-in-content/images-in-content.org
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#+HUGO_SECTION: images-in-content
#+STARTUP: inlineimages

#+AUTHOR:

* Post 1
:PROPERTIES:
:EXPORT_FILE_NAME: post1
Expand Down
1 change: 1 addition & 0 deletions test/site/content-org/images-in-content/post3/post3.org
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#+STARTUP: inlineimages

#+TITLE: Post 3
#+AUTHOR:

Post 3 contents

Expand Down
1 change: 1 addition & 0 deletions test/site/content-org/images-in-content/post4/post4.org
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#+STARTUP: inlineimages

#+TITLE: Post 4
#+AUTHOR:

Post 4 contents

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#+HUGO_BASE_DIR: ../../

#+TITLE:
#+AUTHOR:
#+FILETAGS: empty title

This post will be exported without =title= in the front-matter because
Expand Down
1 change: 1 addition & 0 deletions test/site/content-org/single-posts/disable-title-1.org
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#+HUGO_BASE_DIR: ../../

#+TITLE: Disable exporting title
#+AUTHOR:
#+OPTIONS: title:nil

#+FILETAGS: disable title
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#+TITLE: Table with Org markup where the markup is ignored
#+AUTHOR:

# Ignore the Org emphasis characters like * and /
#+OPTIONS: *:nil
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#+TITLE: Hugo auto weight ineffective for per-file exports
#+AUTHOR:

#+HUGO_BASE_DIR: ../../
#+HUGO_WEIGHT: auto
#+HUGO_TAGS: weight
Expand Down
1 change: 1 addition & 0 deletions test/site/content-org/single-posts/post-draft.org
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#+TITLE: Single Post, but draft
#+AUTHOR:
#+DATE: 2017-07-20
#+HUGO_PUBLISHDATE: 2017-07-22
#+HUGO_EXPIRYDATE: 2017-07-23
Expand Down
1 change: 1 addition & 0 deletions test/site/content-org/single-posts/post-toml.org
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#+TITLE: Single Post with TOML front matter
#+AUTHOR:
#+DATE: 2017-07-20
#+HUGO_PUBLISHDATE: 2017-07-22
#+HUGO_EXPIRYDATE: 2017-07-23
Expand Down
1 change: 1 addition & 0 deletions test/site/content-org/single-posts/post-yaml.org
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#+TITLE: Single Post with YAML front matter
#+AUTHOR:
#+DATE: 2017-07-20
#+HUGO_PUBLISHDATE: 2017-07-22
#+HUGO_EXPIRYDATE: 2017-07-23
Expand Down
2 changes: 2 additions & 0 deletions test/site/content-org/src-blocks-with-highlight-shortcode.org
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
# shortcode.
# #+HUGO_CODE_FENCE: t

#+AUTHOR:

#+SEQ_TODO: TODO DRAFT DONE

* Source blocks with Hugo =highlight= shortcode
Expand Down
2 changes: 2 additions & 0 deletions test/site/content-org/tags-and-categories.org
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#+TITLE: My Blog
#+AUTHOR:

#+HUGO_BASE_DIR: ../

#+TAGS: these tags do not get globally applied to the posts
Expand Down
2 changes: 1 addition & 1 deletion test/site/content/alias-test/alias-without-section-2.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
+++
title = "Alias without section portion 2"
aliases = ["/alias-test/alias-b"]
tags = ["aliases"]
tags = ["front-matter", "aliases"]
draft = false
+++

Expand Down
2 changes: 1 addition & 1 deletion test/site/content/posts/alias-different-section.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
+++
title = "Alias specifying a different section"
aliases = ["/alias-test/alias-c"]
tags = ["aliases"]
tags = ["front-matter", "aliases"]
draft = false
+++
2 changes: 1 addition & 1 deletion test/site/content/posts/alias-multiple-with-section.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
+++
title = "Multiple aliases with section portion"
aliases = ["/alias-test/alias-g", "/alias-test/alias-h"]
tags = ["aliases"]
tags = ["front-matter", "aliases"]
draft = false
+++
2 changes: 1 addition & 1 deletion test/site/content/posts/alias-multiple-without-section.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
+++
title = "Multiple aliases without section portion"
aliases = ["/posts/alias-e", "/posts/alias-f"]
tags = ["aliases"]
tags = ["front-matter", "aliases"]
draft = false
+++
2 changes: 1 addition & 1 deletion test/site/content/posts/alias-root-section.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
+++
title = "Alias specifying root section"
aliases = ["/alias-d"]
tags = ["aliases"]
tags = ["front-matter", "aliases"]
draft = false
+++
2 changes: 1 addition & 1 deletion test/site/content/posts/alias-without-section-1.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
+++
title = "Alias without section portion 1"
aliases = ["/posts/alias-a"]
tags = ["aliases"]
tags = ["front-matter", "aliases"]
draft = false
+++

Expand Down
2 changes: 1 addition & 1 deletion test/site/content/posts/auto-set-lastmod.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
+++
title = "Auto-set Lastmod"
lastmod = 2017-12-01T07:02:01-05:00
lastmod = 2017-12-01T16:24:29-05:00
tags = ["dont-export-during-make-test"]
draft = false
+++
Expand Down
8 changes: 8 additions & 0 deletions test/site/content/posts/disable-author.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
+++
title = "Disable exporting author"
tags = ["export-option", "author", "disable"]
draft = false
+++

This post will be exported without `author` in the front-matter because
it is disabled using `:EXPORT_OPTIONS: author:nil`.
9 changes: 9 additions & 0 deletions test/site/content/posts/multiple-authors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
+++
title = "Multiple authors"
author = ["Foo Bar", "Toto Kumar", "Zulu", "Ágota Kristóf"]
tags = ["front-matter", "author"]
draft = false
+++

This post has multiple authors. In Org, multiple authors are added
comma-separated.
8 changes: 8 additions & 0 deletions test/site/content/posts/single-author.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
+++
title = "Single author"
author = ["Foo Bar"]
tags = ["front-matter", "author"]
draft = false
+++

This post has 1 author.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
+++
title = "Multifractals in ecology using R"
author = ["Leonardo A. Saravia"]
date = 2017-11-28T10:48:00-05:00
tags = ["real-examples", "math", "equations"]
draft = false
author = "Leonardo A. Saravia"
source = "https://github.com/lsaravia/MultifractalsInR/blob/master/Curso3.md"
+++

Expand Down
2 changes: 2 additions & 0 deletions test/site/content/real-examples/nn-intro.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
+++
title = "神经网络基础"
author = ["Feng Ruohang"]
date = 2017-11-29
tags = ["real-examples", "math", "equations", "not-english", "table", "latex", "latex-environment"]
draft = false
source = "https://github.com/Vonng/Math/blob/master/nndl/nn-intro.md"
+++

- **Disclaimer:** This post is from the [link](https://github.com/Vonng/Math/blob/master/nndl/nn-intro.md) posted by GitHub user
Expand Down
5 changes: 3 additions & 2 deletions test/site/content/writing-hugo-blog-in-org-file-export.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
+++
title = "Writing Hugo blog in Org (File Export)"
author = ["Kaushal Modi"]
date = 2017-09-10
lastmod = 2017-11-30T14:21:54-05:00
tags = ["hugo", "org", "dont_export_during_make_test"]
lastmod = 2017-12-01T16:23:22-05:00
tags = ["hugo", "org"]
categories = ["emacs"]
weight = 2001
draft = true
Expand Down
3 changes: 2 additions & 1 deletion test/site/content/writing-hugo-blog-in-org-subtree-export.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
+++
title = "Writing Hugo blog in Org"
author = ["Kaushal Modi"]
date = 2017-09-10
lastmod = 2017-11-30T14:22:00-05:00
lastmod = 2017-12-01T16:24:07-05:00
tags = ["dont-export-during-make-test", "hugo", "org"]
categories = ["emacs"]
weight = 2001
Expand Down

0 comments on commit 852ab6c

Please sign in to comment.