Skip to content

Commit

Permalink
Fix quite a few Org keywords that couldn't be merged
Browse files Browse the repository at this point in the history
For many keywords like #+HUGO_TAGS, it is useful to merge multiple
values when this is done:

    #+HUGO_TAGS: value1
    #+HUGO_TAGS: value2

This merging did not happen as expected for these keywords; this
commit fixes that.

    #+AUTHOR:
    #+HUGO_CUSTOM_FRONT_MATTER:
    #+HUGO_BLACKFRIDAY:
    #+HUGO_MENU:
    #+HUGO_MENU_OVERRIDE:
    #+HUGO_OUTPUTS:
    #+HUGO_RESOURCES:

Add test case for the same.

(Note that this fix was needed only for Org keyword values merging, not
subtree property merging.)
  • Loading branch information
kaushalmodi committed Jan 25, 2018
1 parent ec94942 commit 38eba6d
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 8 deletions.
19 changes: 11 additions & 8 deletions ox-hugo.el
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,7 @@ newer."
:options-alist '(;; Variables not setting the front-matter directly
(:with-toc nil "toc" org-hugo-export-with-toc)
(:section-numbers nil "num" org-hugo-export-with-section-numbers)
(:author "AUTHOR" nil org-export-with-author newline)
(:creator "CREATOR" nil org-hugo-export-creator-string)
(:with-smart-quotes nil "'" nil) ;Don't use smart quotes; that is done automatically by Blackfriday
(:with-special-strings nil "-" nil) ;Don't use special strings for ndash, mdash; that is done automatically by Blackfriday
Expand All @@ -656,14 +657,12 @@ newer."
(:hugo-bundle "HUGO_BUNDLE" nil nil)
(:hugo-base-dir "HUGO_BASE_DIR" nil nil)
(:hugo-code-fence "HUGO_CODE_FENCE" nil t) ;Prefer to generate triple-backquoted Markdown code blocks by default.
(:hugo-menu "HUGO_MENU" nil nil)
(:hugo-menu-override "HUGO_MENU_OVERRIDE" nil nil)
(:hugo-use-code-for-kbd "HUGO_USE_CODE_FOR_KBD" nil org-hugo-use-code-for-kbd)
(:hugo-prefer-hyphen-in-tags "HUGO_PREFER_HYPHEN_IN_TAGS" nil org-hugo-prefer-hyphen-in-tags)
(:hugo-allow-spaces-in-tags "HUGO_ALLOW_SPACES_IN_TAGS" nil org-hugo-allow-spaces-in-tags)
(:hugo-auto-set-lastmod "HUGO_AUTO_SET_LASTMOD" nil org-hugo-auto-set-lastmod)
(:hugo-custom-front-matter "HUGO_CUSTOM_FRONT_MATTER" nil nil)
(:hugo-blackfriday "HUGO_BLACKFRIDAY" nil nil)
(:hugo-custom-front-matter "HUGO_CUSTOM_FRONT_MATTER" nil nil space)
(:hugo-blackfriday "HUGO_BLACKFRIDAY" nil nil space)
(:hugo-front-matter-key-replace "HUGO_FRONT_MATTER_KEY_REPLACE" nil nil space)

;; Front matter variables
Expand Down Expand Up @@ -697,8 +696,11 @@ newer."
(:hugo-linktitle "HUGO_LINKTITLE" nil nil)
;; markup
(:hugo-markup "HUGO_MARKUP" nil nil) ;default is "md"
;; menu
(:hugo-menu "HUGO_MENU" nil nil space)
(:hugo-menu-override "HUGO_MENU_OVERRIDE" nil nil space)
;; outputs
(:hugo-outputs "HUGO_OUTPUTS" nil nil)
(:hugo-outputs "HUGO_OUTPUTS" nil nil space)
;; publishDate
(:hugo-publishdate "HUGO_PUBLISHDATE" nil nil)
;; slug
Expand All @@ -718,7 +720,7 @@ newer."
;; override inherited categories and Org-style
;; categories (Org-style tags with "@" prefix).
;; resources
(:hugo-resources "HUGO_RESOURCES" nil nil)
(:hugo-resources "HUGO_RESOURCES" nil nil space)
;; title
;; "title" is parsed from the Org #+TITLE or the subtree heading.
;; type
Expand Down Expand Up @@ -2237,8 +2239,9 @@ INFO is a plist used as a communication channel."
(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 ",")))
;; Multiple authors can be comma or
;; newline separated.
(let ((author-list-1 (org-split-string author-raw "[,\n]")))
;; Don't allow spaces around author names.
(mapcar #'org-trim author-list-1))))))
(creator (and (plist-get info :with-creator)
Expand Down
90 changes: 90 additions & 0 deletions test/site/content-org/keyword-collection.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#+TITLE: Keyword Collection

#+HUGO_BASE_DIR: ../

# Authors
#+AUTHOR: firstname1 lastname1
#+AUTHOR: firstname2 lastname2, firstname3 lastname3

# Note that #+FILETAGS won't work in file-based exports (like this one).
# https://ox-hugo.scripter.co/doc/tags-and-categories/#file-based-export

# Tags
#+HUGO_TAGS: mega__front-matter
#+HUGO_TAGS: keys
#+HUGO_TAGS: collection concatenation merging

# Categories
#+HUGO_CATEGORIES: cat1
#+HUGO_CATEGORIES: cat2

# Menu
#+HUGO_MENU: :menu foo
#+HUGO_MENU: :weight 10

# # Menu Override
# #+HUGO_MENU_OVERRIDE: :menu bar
# #+HUGO_MENU_OVERRIDE: :weight 20

# Custom front-matter
#+HUGO_CUSTOM_FRONT_MATTER: :foo bar
#+HUGO_CUSTOM_FRONT_MATTER: :baz zoo
#+HUGO_CUSTOM_FRONT_MATTER: :alpha 1
#+HUGO_CUSTOM_FRONT_MATTER: :beta "two words"
#+HUGO_CUSTOM_FRONT_MATTER: :gamma 10
#+HUGO_CUSTOM_FRONT_MATTER: :animals '(dog cat "penguin" "mountain gorilla")
#+HUGO_CUSTOM_FRONT_MATTER: :strings-symbols '("abc" def "two words")
#+HUGO_CUSTOM_FRONT_MATTER: :integers '(123 -5 17 1_234)
#+HUGO_CUSTOM_FRONT_MATTER: :floats '(12.3 -5.0 -17E-6)
#+HUGO_CUSTOM_FRONT_MATTER: :booleans '(true false)

# Blackfriday
#+HUGO_BLACKFRIDAY: :smartdashes :fractions nil :plainidanchors false
#+HUGO_BLACKFRIDAY: :angledquotes t :hrefTargetBlank true
#+HUGO_BLACKFRIDAY: :extensions tabsizeeight hardlinebreak
#+HUGO_BLACKFRIDAY: :extensionsmask fencedcode strikethrough

# Front-matter key replacement
#+HUGO_FRONT_MATTER_KEY_REPLACE: foo>myfoo
#+HUGO_FRONT_MATTER_KEY_REPLACE: baz>mybaz

# Aliases
#+HUGO_ALIASES: keyword-concatenation
#+HUGO_ALIASES: keyword-merging

# Keywords
#+KEYWORDS: keyword1 keyword2
#+KEYWORDS: three__word__keywords3

# Outputs
#+HUGO_OUTPUTS: html
#+HUGO_OUTPUTS: json

# Resources
#+HUGO_RESOURCES: :src "*.png" :animals '(dog cat "penguin" "mountain gorilla")
#+HUGO_RESOURCES: :strings-symbols '("abc" def "two words")
#+HUGO_RESOURCES: :integers '(123 -5 17 1_234)
#+HUGO_RESOURCES: :floats '(12.3 -5.0 -17E-6)
#+HUGO_RESOURCES: :booleans '(true false)
#+HUGO_RESOURCES: :foo bar
#+HUGO_RESOURCES: :src "image-4.png" :title "The Fourth Image"
#+HUGO_RESOURCES: :src "*.png" :name "my-cool-image-:counter" :title "The Image #:counter"
#+HUGO_RESOURCES: :src "*.png" :byline "bep"
#+HUGO_RESOURCES: :src "*.jpg" :title "JPEG Image #:counter"

This is a test post that tests that keywords set across multiple Org
keywords get collected.

* Keyword Collection Tested to work [12/12]
- [X] =#+AUTHOR=
- [X] =#+HUGO_TAGS=
- [X] =#+HUGO_CATEGORIES=
- [X] =#+HUGO_MENU=
- [X] =#+HUGO_MENU_OVERRIDE=
- [X] =#+HUGO_CUSTOM_FRONT_MATTER=
- [X] =#+HUGO_BLACKFRIDAY=
- [X] =#+HUGO_FRONT_MATTER_KEY_REPLACE=
- [X] =#+HUGO_ALIASES=
- [X] =#+KEYWORDS=
- [X] =#+HUGO_OUTPUTS=
- [X] =#+HUGO_RESOURCES=
68 changes: 68 additions & 0 deletions test/site/content/posts/keyword-collection.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
+++
title = "Keyword Collection"
author = ["firstname1 lastname1", "firstname2 lastname2", "firstname3 lastname3"]
aliases = ["/posts/keyword-concatenation", "/posts/keyword-merging"]
keywords = ["keyword1", "keyword2", "three word keywords3"]
outputs = ["html", "json"]
tags = ["mega front-matter", "keys", "collection", "concatenation", "merging"]
categories = ["cat1", "cat2"]
draft = false
myfoo = "bar"
mybaz = "zoo"
alpha = 1
beta = "two words"
gamma = 10
animals = ["dog", "cat", "penguin", "mountain gorilla"]
strings-symbols = ["abc", "def", "two words"]
integers = [123, -5, 17, 1_234]
floats = [12.3, -5.0, -1.7e-05]
booleans = [true, false]
[blackfriday]
extensionsmask = ["fencedCode", "strikethrough"]
extensions = ["tabSizeEight", "hardLineBreak"]
plainIDAnchors = false
hrefTargetBlank = true
smartDashes = false
fractions = false
angledQuotes = true
[menu.foo]
identifier = "keyword-collection"
weight = 10
[[resources]]
src = "*.png"
name = "my-cool-image-:counter"
title = "The Image #:counter"
[resources.params]
foo = "bar"
floats = [12.3, -5.0, -1.7e-05]
strings-symbols = ["abc", "def", "two words"]
animals = ["dog", "cat", "penguin", "mountain gorilla"]
integers = [123, -5, 17, 1_234]
booleans = [true, false]
byline = "bep"
[[resources]]
src = "image-4.png"
title = "The Fourth Image"
[[resources]]
src = "*.jpg"
title = "JPEG Image #:counter"
+++

This is a test post that tests that keywords set across multiple Org
keywords get collected.


## Keyword Collection Tested to work <code>[12/12]</code> {#keyword-collection-tested-to-work}

- [X] `#+AUTHOR`
- [X] `#+HUGO_TAGS`
- [X] `#+HUGO_CATEGORIES`
- [X] `#+HUGO_MENU`
- [X] `#+HUGO_MENU_OVERRIDE`
- [X] `#+HUGO_CUSTOM_FRONT_MATTER`
- [X] `#+HUGO_BLACKFRIDAY`
- [X] `#+HUGO_FRONT_MATTER_KEY_REPLACE`
- [X] `#+HUGO_ALIASES`
- [X] `#+KEYWORDS`
- [X] `#+HUGO_OUTPUTS`
- [X] `#+HUGO_RESOURCES`

0 comments on commit 38eba6d

Please sign in to comment.