Skip to content

Commit

Permalink
Merge pull request #629 from kaushalmodi/use-tomelr
Browse files Browse the repository at this point in the history
feat!: Use tomelr for TOML front-matter generation
  • Loading branch information
kaushalmodi committed May 4, 2022
2 parents 262b7b4 + 887df91 commit a834511
Show file tree
Hide file tree
Showing 39 changed files with 569 additions and 485 deletions.
333 changes: 332 additions & 1 deletion ox-hugo-deprecated.el

Large diffs are not rendered by default.

39 changes: 39 additions & 0 deletions ox-hugo-pandoc-cite.el
Expand Up @@ -357,6 +357,45 @@ INFO is a plist used as a communication channel."
(org-hugo-pandoc-cite--restore-fm-in-orig-outfile
orig-outfile fm orig-outfile-contents))))

(defun org-hugo-pandoc-cite--meta-data-generator (data)
"Return YAML front-matter to pass citation meta-data to Pandoc.
DATA is the alist containing all the post meta-data for
front-matter generation.
Pandoc accepts `csl', `nocite' and `link-citations' variables via
a YAML front-matter.
References:
- https://pandoc.org/MANUAL.html#citation-rendering
- https://pandoc.org/MANUAL.html#including-uncited-items-in-the-bibliography
- https://pandoc.org/MANUAL.html#other-relevant-metadata-fields"
(let* ((yaml ())
(link-citations (cdr (assoc 'link-citations data)))
(link-citations (if (symbolp link-citations)
(symbol-name link-citations)
link-citations))
(csl (cdr (assoc 'csl data)))
(nocite (cdr (assoc 'nocite data))))
(push "---" yaml)
(when link-citations
(push (format "link-citations: %s"
(org-hugo--front-matter-value-booleanize link-citations))
yaml))
(when csl
(push (format "csl: %S" csl) yaml))
(when nocite
(push (format "nocite: [%s]"
(string-join
(mapcar (lambda (elem)
(format "%S" (symbol-name elem)))
nocite)
", "))
yaml))
(push "---\n" yaml)
;; (message "[org-hugo-pandoc-cite--meta-data-generator DBG] yaml: %S" yaml)
(string-join (nreverse yaml) "\n")))


(provide 'ox-hugo-pandoc-cite)

Expand Down
472 changes: 70 additions & 402 deletions ox-hugo.el

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion test/setup-ox-hugo.el
Expand Up @@ -110,7 +110,7 @@ Emacs installation. If Emacs is installed using
(when ox-hugo-test-setup-verbose
(message "ox-hugo-tmp-dir: %s" ox-hugo-tmp-dir))

(defvar ox-hugo-packages '(toc-org citeproc org-ref))
(defvar ox-hugo-packages '(toc-org citeproc org-ref tomelr))
(when ox-hugo-install-org-from-elpa
;; Fri Sep 22 18:24:19 EDT 2017 - kmodi
;; Install the packages in the specified order. We do not want
Expand Down Expand Up @@ -160,6 +160,12 @@ Emacs installation. If Emacs is installed using
(add-to-list 'package-archives (cons "melpa" melpa-url) :append) ;For `toc-org', `citeproc'
)

;; Workaround for this error on GHA when using Emacs 26.3:
;; signal(file-error ("https://elpa.gnu.org/packages/tomelr-0.2.2.tar" "Bad Request"))
(when (version< emacs-version "27.0")
;; https://lists.gnu.org/archive/html/help-gnu-emacs/2020-01/msg00162.html
(setq gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3"))

;; Delete element with "nongnu" car from `package-archives'.
(setq package-archives (delq (assoc "nongnu" package-archives) package-archives))

Expand Down
2 changes: 1 addition & 1 deletion test/site/content-org/all-posts.org
Expand Up @@ -7556,7 +7556,7 @@ the ~.Permalink~ and ~.RelPermalink~ get set to ~""~.
*** _build: Don't render or list this page :dont_render:dont_list:headless:
:PROPERTIES:
:EXPORT_FILE_NAME: do-not-render-or-list
:EXPORT_HUGO_CUSTOM_FRONT_MATTER: :_build '((render . nil) (list . nil))
:EXPORT_HUGO_CUSTOM_FRONT_MATTER: :_build '((render . false) (list . false))
:END:
#+begin_description
Do not render or list this page.
Expand Down
2 changes: 1 addition & 1 deletion test/site/content-org/keyword-collection.org
Expand Up @@ -60,14 +60,14 @@
#+hugo_outputs: json

# Resources
#+hugo_resources: :src "*.png" :name "my-cool-image-:counter" :title "The Image #:counter"
#+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"

Expand Down
2 changes: 1 addition & 1 deletion test/site/content-org/single-posts/post-toml.org
Expand Up @@ -2,7 +2,7 @@
#+author:
#+date: 2017-07-20

#+filetags: single toml "cross-link" @cat1 @cat2
#+filetags: single toml cross-link @cat1 @cat2

#+hugo_base_dir: ../../
#+hugo_section: singles
Expand Down
Expand Up @@ -8,6 +8,7 @@ baz = "zoo"
alpha = 1
beta = "two words"
gamma = 10
empty_string = ""
+++

From [**(org) Property Syntax**](https://orgmode.org/manual/Property-Syntax.html):
Expand Down
Expand Up @@ -12,7 +12,6 @@ draft = false
caption = "stay hungry, stay foolish"
[collection]
animals = ["dog", "cat", "penguin", "mountain gorilla"]
nothing = false
nonnil = true
strings-symbols = ["abc", "def", "two words"]
integers = [123, -5, 17, 1_234]
Expand Down
4 changes: 3 additions & 1 deletion test/site/content/posts/hugo-keyword.md
@@ -1,6 +1,8 @@
+++
title = "Hugo keyword"
description = "Stuff followed the `#+hugo:` exports as-is except when it is \"more\""
description = """
Stuff followed the `#+hugo:` exports as-is except when it is "more"
"""
tags = ["body", "keyword", "hugo"]
draft = false
+++
Expand Down
@@ -1,7 +1,8 @@
+++
title = "Post with menu 1 (HUGO_MENU as keyword)"
draft = false
[menu."auto weight"]
weight = 1001
identifier = "post-with-menu-1-hugo-menu-as-keyword"
[menu]
[menu."auto weight"]
weight = 1001
identifier = "post-with-menu-1-hugo-menu-as-keyword"
+++
@@ -1,7 +1,8 @@
+++
title = "Post with menu 2 (HUGO_MENU as keyword)"
draft = false
[menu."auto weight"]
weight = 1002
identifier = "post-with-menu-2-hugo-menu-as-keyword"
[menu]
[menu."auto weight"]
weight = 1002
identifier = "post-with-menu-2-hugo-menu-as-keyword"
+++
@@ -1,7 +1,8 @@
+++
title = "Post with menu 3 (HUGO_MENU as keyword)"
draft = false
[menu."auto weight"]
weight = 1003
identifier = "post-with-menu-3-hugo-menu-as-keyword"
[menu]
[menu."auto weight"]
weight = 1003
identifier = "post-with-menu-3-hugo-menu-as-keyword"
+++
@@ -1,7 +1,8 @@
+++
title = "Post with menu 4 (HUGO_MENU as keyword)"
draft = false
[menu."auto weight"]
weight = 1004
identifier = "post-with-menu-4-hugo-menu-as-keyword"
[menu]
[menu."auto weight"]
weight = 1004
identifier = "post-with-menu-4-hugo-menu-as-keyword"
+++
@@ -1,7 +1,8 @@
+++
title = "Post with menu 5 (HUGO_MENU as keyword)"
draft = false
[menu."auto weight"]
weight = 1005
identifier = "post-with-menu-5-hugo-menu-as-keyword"
[menu]
[menu."auto weight"]
weight = 1005
identifier = "post-with-menu-5-hugo-menu-as-keyword"
+++
8 changes: 4 additions & 4 deletions test/site/content/posts/keyword-collection.md
Expand Up @@ -31,16 +31,16 @@ booleans = [true, false]
image = "projects/Readingabook.jpg"
caption = "stay hungry, stay foolish"
[collection]
nothing = false
nonnil = true
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]
[menu.foo]
identifier = "keyword-collection"
weight = 10
[menu]
[menu.foo]
identifier = "keyword-collection"
weight = 10
[[resources]]
src = "*.png"
name = "my-cool-image-:counter"
Expand Down
Expand Up @@ -3,9 +3,10 @@ title = "Overriding menu properties completely"
date = 2017-07-18
tags = ["menu"]
draft = false
[menu.test]
identifier = "overriding-menu-properties-completely"
weight = 50
[menu]
[menu.test]
identifier = "overriding-menu-properties-completely"
weight = 50
+++

For this post, we see that no menu properties are inherited from the
Expand Down
Expand Up @@ -3,10 +3,11 @@ title = "Overriding few menu properties"
date = 2017-07-18
tags = ["menu"]
draft = false
[menu."something here"]
parent = "posts"
weight = 10
identifier = "ov-partial"
[menu]
[menu."something here"]
parent = "posts"
weight = 10
identifier = "ov-partial"
+++

For this post, we should see just the menu _weight_ and _identifier_
Expand Down
4 changes: 2 additions & 2 deletions test/site/content/posts/menu-meta-data-yaml.md
Expand Up @@ -5,9 +5,9 @@ tags: ["menu", "yaml"]
draft: false
menu:
main:
identifier: "yaml-menu-override"
weight: 25
parent: "posts"
weight: 25
identifier: "yaml-menu-override"
---

Testing the addition of _menu_ meta data to the YAML front
Expand Down
9 changes: 5 additions & 4 deletions test/site/content/posts/menu-title-property.md
Expand Up @@ -2,10 +2,11 @@
title = "Menu Title property"
tags = ["menu", "title"]
draft = false
[menu.test]
weight = 3003
identifier = "menu-title-property"
title = "Page title for menu"
[menu]
[menu.test]
weight = 3003
identifier = "menu-title-property"
title = "Page title for menu"
+++

The `title` property for menu entries was introduced in Hugo v0.32 in
Expand Down
8 changes: 6 additions & 2 deletions test/site/content/posts/post-description-quotes.md
@@ -1,6 +1,10 @@
+++
title = "Description meta-data with \"quoted text\""
description = "Some description with \"quoted text\""
title = """
Description meta-data with "quoted text"
"""
description = """
Some description with "quoted text"
"""
date = 2017-07-24
tags = ["front-matter", "description"]
draft = false
Expand Down
4 changes: 3 additions & 1 deletion test/site/content/posts/post-title-quotes.md
@@ -1,5 +1,7 @@
+++
title = "Awesome title with \"quoted text\""
title = """
Awesome title with "quoted text"
"""
date = 2017-07-24
tags = ["title"]
draft = false
Expand Down
7 changes: 4 additions & 3 deletions test/site/content/posts/post-with-menu-1.md
Expand Up @@ -3,7 +3,8 @@ title = "Post with menu 1"
date = 2017-07-20
tags = ["menu"]
draft = false
[menu."auto weight"]
weight = 4001
identifier = "post-with-menu-1"
[menu]
[menu."auto weight"]
weight = 4001
identifier = "post-with-menu-1"
+++
7 changes: 4 additions & 3 deletions test/site/content/posts/post-with-menu-2.md
Expand Up @@ -3,7 +3,8 @@ title = "Post with menu 2"
date = 2017-07-20
tags = ["menu"]
draft = false
[menu."auto weight"]
weight = 4002
identifier = "post-with-menu-2"
[menu]
[menu."auto weight"]
weight = 4002
identifier = "post-with-menu-2"
+++
7 changes: 4 additions & 3 deletions test/site/content/posts/post-with-menu-3.md
Expand Up @@ -3,7 +3,8 @@ title = "Post with menu 3"
date = 2017-07-20
tags = ["menu"]
draft = false
[menu."auto weight"]
weight = 4003
identifier = "post-with-menu-3"
[menu]
[menu."auto weight"]
weight = 4003
identifier = "post-with-menu-3"
+++
7 changes: 4 additions & 3 deletions test/site/content/posts/post-with-menu-4.md
Expand Up @@ -3,7 +3,8 @@ title = "Post with menu 4"
date = 2017-07-20
tags = ["menu"]
draft = false
[menu."auto weight"]
weight = 4004
identifier = "post-with-menu-4"
[menu]
[menu."auto weight"]
weight = 4004
identifier = "post-with-menu-4"
+++
7 changes: 4 additions & 3 deletions test/site/content/posts/post-with-menu-5.md
Expand Up @@ -3,7 +3,8 @@ title = "Post with menu 5"
date = 2017-07-20
tags = ["menu"]
draft = false
[menu."auto weight"]
weight = 4005
identifier = "post-with-menu-5"
[menu]
[menu."auto weight"]
weight = 4005
identifier = "post-with-menu-5"
+++
@@ -1,5 +1,7 @@
+++
title = "Replace both \"tags\" and \"categories\" keys"
title = """
Replace both "tags" and "categories" keys
"""
keywords = ["front-matter", "keys", "replace", "tags", "categories"]
cats = ["test-cat-x"]
draft = false
Expand Down
4 changes: 3 additions & 1 deletion test/site/content/posts/replace-description-with-summary.md
@@ -1,5 +1,7 @@
+++
title = "Replace \"description\" with \"summary\""
title = """
Replace "description" with "summary"
"""
summary = """
This should be rendered as `.Summary` in Hugo v0.55+. For only Hugo
versions, this will front-matter can be retrieved only as
Expand Down
4 changes: 3 additions & 1 deletion test/site/content/posts/replace-only-categories-key.md
@@ -1,5 +1,7 @@
+++
title = "Replace only \"categories\" key"
title = """
Replace only "categories" key
"""
tags = ["front-matter", "keys", "replace", "categories"]
cats = ["test-cat-x"]
draft = false
Expand Down
8 changes: 6 additions & 2 deletions test/site/content/posts/replace-only-linktitle-key.md
@@ -1,6 +1,10 @@
+++
title = "Replace only \"linkTitle\" key"
linktitle = "Replace only \"linkTitle\" key"
title = """
Replace only "linkTitle" key
"""
linktitle = """
Replace only "linkTitle" key
"""
tags = ["front-matter", "keys", "replace", "linktitle"]
draft = false
+++
Expand Down
4 changes: 3 additions & 1 deletion test/site/content/posts/replace-only-tags-key.md
@@ -1,5 +1,7 @@
+++
title = "Replace only \"tags\" key"
title = """
Replace only "tags" key
"""
keywords = ["front-matter", "keys", "replace", "tags"]
draft = false
+++
Expand Down

0 comments on commit a834511

Please sign in to comment.