Skip to content

Commit

Permalink
Remove unnecessary org-export-data forms
Browse files Browse the repository at this point in the history
Add tests for type, layout, url, slug, linktitle and markup
front-matter.

Fixes #52
  • Loading branch information
kaushalmodi committed Feb 6, 2018
1 parent d62d38d commit 79616a3
Show file tree
Hide file tree
Showing 12 changed files with 199 additions and 22 deletions.
41 changes: 19 additions & 22 deletions ox-hugo.el
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,8 @@ cannot be formatted in Hugo-compatible format."
(let* ((date-fmt (plist-get info :hugo-date-format))
(date-raw (cond
((equal date-key :date)
;; (message "[ox-hugo date DBG] 1 %s" (plist-get info date-key))
;; (message "[ox-hugo date DBG] 2 %s" (org-export-data (plist-get info date-key) info))
(or
;; Get the date from the "CLOSED" property;
;; generated automatically when switching a
Expand All @@ -1188,7 +1190,7 @@ cannot be formatted in Hugo-compatible format."
;; Else get the date from the subtree property,
;; `EXPORT_DATE' if available,
(org-string-nw-p
(org-export-data (plist-get info date-key) info))
(org-export-data (plist-get info date-key) info)) ;`org-export-data' required
;; Else try to get it from the #+date keyword in
;; the Org file.
(org-string-nw-p
Expand All @@ -1202,8 +1204,7 @@ cannot be formatted in Hugo-compatible format."
;; Get the date from the "DEADLINE" property.
(org-entry-get (point) "DEADLINE"))
(t ;:hugo-lastmod, :hugo-publishdate, :hugo-expirydate
(org-string-nw-p
(org-export-data (plist-get info date-key) info)))))
(org-string-nw-p (plist-get info date-key)))))
(date-nocolon (cond
;; If the date set for the DATE-KEY parameter
;; is already in Hugo-compatible format, use
Expand Down Expand Up @@ -1423,11 +1424,11 @@ a communication channel."
(unless (org-element-property :footnote-section-p headline)
(let* ((numbers (org-hugo--get-headline-number headline info nil))
(level (org-export-get-relative-level headline info))
(title (org-export-data (org-element-property :title headline) info))
(todo (and (org-hugo--plist-get-true-p info :with-todo-keywords)
(let ((todo (org-element-property :todo-keyword
headline)))
(and todo (concat (org-export-data todo info) " ")))))
(title (org-export-data (org-element-property :title headline) info)) ;`org-export-data' required
(todo (let ((todo1 (and (org-hugo--plist-get-true-p info :with-todo-keywords)
(org-element-property :todo-keyword headline))))
(when (stringp todo1)
(format "%s " todo1))))
(tags (and (org-hugo--plist-get-true-p info :with-tags)
(let ((tag-list (org-export-get-tags headline info)))
(and tag-list
Expand Down Expand Up @@ -2542,7 +2543,7 @@ INFO is a plist used as a communication channel."
(author-list (and (plist-get info :with-author)
(let ((author-raw
(org-string-nw-p
(org-export-data (plist-get info :author) info))))
(org-export-data (plist-get info :author) info)))) ;`org-export-data' required
(when author-raw
;; Multiple authors can be comma or
;; newline separated.
Expand All @@ -2561,11 +2562,8 @@ INFO is a plist used as a communication channel."
(replace-regexp-in-string "\\`\\([a-z]+_[A-Z]+\\).*\\'" "\\1" lang))))
lang)))
(description (or org-hugo--description
(org-string-nw-p
(org-export-data (plist-get info :description) info))))
(aliases-raw (let ((aliases-raw-1
(org-string-nw-p
(org-export-data (plist-get info :hugo-aliases) info))))
(org-string-nw-p (plist-get info :description))))
(aliases-raw (let ((aliases-raw-1 (org-string-nw-p (plist-get info :hugo-aliases))))
(when aliases-raw-1
(org-split-string aliases-raw-1 " "))))
(aliases (let (alias-list)
Expand All @@ -2576,8 +2574,7 @@ INFO is a plist used as a communication channel."
(setq alias (concat "/" section alias))))
(setq alias-list (append alias-list `(,alias))))
alias-list))
(outputs-raw (org-string-nw-p
(org-export-data (plist-get info :hugo-outputs) info)))
(outputs-raw (org-string-nw-p (plist-get info :hugo-outputs)))
(outputs (when outputs-raw
(org-split-string outputs-raw " ")))
(todo-keyword (org-entry-get (point) "TODO"))
Expand Down Expand Up @@ -2663,17 +2660,17 @@ INFO is a plist used as a communication channel."
(images . ,(org-hugo--delim-str-to-list (plist-get info :hugo-images)))
(isCJKLanguage . ,(org-hugo--plist-get-true-p info :hugo-iscjklanguage))
(keywords . ,keywords)
(layout . ,(org-export-data (plist-get info :hugo-layout) info))
(layout . ,(plist-get info :hugo-layout))
(lastmod . ,(org-hugo--format-date :hugo-lastmod info))
(linkTitle . ,(org-export-data (plist-get info :hugo-linktitle) info))
(markup . ,(org-export-data (plist-get info :hugo-markup) info))
(linkTitle . ,(plist-get info :hugo-linktitle))
(markup . ,(plist-get info :hugo-markup))
(outputs . ,outputs)
(series . ,(org-hugo--delim-str-to-list (plist-get info :hugo-series)))
(slug . ,(org-export-data (plist-get info :hugo-slug) info))
(slug . ,(plist-get info :hugo-slug))
(tags . ,tags)
(categories . ,categories)
(type . ,(org-export-data (plist-get info :hugo-type) info))
(url . ,(org-export-data (plist-get info :hugo-url) info))
(type . ,(plist-get info :hugo-type))
(url . ,(plist-get info :hugo-url))
(videos . ,(org-hugo--delim-str-to-list (plist-get info :hugo-videos)))
(weight . ,weight)
(draft . ,draft)
Expand Down
64 changes: 64 additions & 0 deletions test/site/content-org/all-posts.org
Original file line number Diff line number Diff line change
Expand Up @@ -4373,6 +4373,70 @@ quotes.
:END:
If a series name has spaces in it, wrap the whole name in double
quotes.
** Type :type:
*** Type Front-matter
:PROPERTIES:
:EXPORT_FILE_NAME: type-front-matter
:EXPORT_HUGO_TYPE: type-test
:END:
The =type= front-matter is used to override the default *section* type
(automatically derived from the directory of the content page).

Here the type is overridden to be =type-test=.

[[https://gohugo.io/content-management/front-matter/#predefined][Reference]]
*** Type + Layout Front-matter :layout:
:PROPERTIES:
:EXPORT_FILE_NAME: type-and-layout-front-matter
:EXPORT_HUGO_TYPE: type-test
:EXPORT_HUGO_LAYOUT: alternate-single
:END:
Here both =type= *and* =layout= are overridden.
** Layout Front-matter :layout:
:PROPERTIES:
:EXPORT_FILE_NAME: layout-front-matter
:EXPORT_HUGO_LAYOUT: alternate-single
:END:
The =layout= front-matter is used to override the default *single*
layout of a regular page. See [[https://gohugo.io/templates/lookup-order/][Template Lookup Order]] to learn more.

Here the layout is overridden to be =alternate-single=.

[[https://gohugo.io/content-management/front-matter/#predefined][Reference]]
** URL Front-matter :url:
:PROPERTIES:
:EXPORT_FILE_NAME: url-front-matter
:EXPORT_HUGO_URL: foo/bar/zoo/url-front-matter
:END:
The =url= front-matter is used to specify *the full path to the
content from the web root*. It makes no assumptions about the path of
the content file. It also ignores any language prefixes of the
multilingual feature.

[[https://gohugo.io/content-management/front-matter/#predefined][Reference]]
** Linktitle Front-matter :linktitle:
:PROPERTIES:
:EXPORT_FILE_NAME: linktitle-front-matter
:EXPORT_HUGO_LINKTITLE: My link title
:END:
The =linktitle= front-matter is used for creating links to content. If
set, Hugo defaults to using the =linktitle= before the =title=.
** Slug Front-matter :slug:
:PROPERTIES:
:EXPORT_FILE_NAME: slug-front-matter
:EXPORT_HUGO_SLUG: this-is-how-i-want-to-name-this-link
:END:
By default, a page's /slug/ is the name of the content file (sans
extension). So in this case, it would have been
=slug-front-matter=. But that slug is overridden using the specified
=slug= in the front-matter: =this-is-how-i-want-to-name-this-link=.
** Markup Front-matter :markup:
:PROPERTIES:
:EXPORT_FILE_NAME: markup-front-matter
:EXPORT_HUGO_MARKUP: org
:END:
The markup for this post is set to =org=. So the Markdown markup based
emphasis *won't work* here.
** Replace front-matter keys :keys:replace:
*** Replace only "linkTitle" key :linktitle:
:PROPERTIES:
Expand Down
13 changes: 13 additions & 0 deletions test/site/content/posts/layout-front-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
+++
title = "Layout Front-matter"
layout = "alternate-single"
tags = ["front-matter", "layout"]
draft = false
+++

The `layout` front-matter is used to override the default **single**
layout of a regular page. See [Template Lookup Order](https://gohugo.io/templates/lookup-order/) to learn more.

Here the layout is overridden to be `alternate-single`.

[Reference](https://gohugo.io/content-management/front-matter/#predefined)
9 changes: 9 additions & 0 deletions test/site/content/posts/linktitle-front-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
+++
title = "Linktitle Front-matter"
linkTitle = "My link title"
tags = ["front-matter", "linktitle"]
draft = false
+++

The `linktitle` front-matter is used for creating links to content. If
set, Hugo defaults to using the `linktitle` before the `title`.
9 changes: 9 additions & 0 deletions test/site/content/posts/markup-front-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
+++
title = "Markup Front-matter"
markup = "org"
tags = ["front-matter", "markup"]
draft = false
+++

The markup for this post is set to `org`. So the Markdown markup based
emphasis **won't work** here.
11 changes: 11 additions & 0 deletions test/site/content/posts/slug-front-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
+++
title = "Slug Front-matter"
slug = "this-is-how-i-want-to-name-this-link"
tags = ["front-matter", "slug"]
draft = false
+++

By default, a page's _slug_ is the name of the content file (sans
extension). So in this case, it would have been
`slug-front-matter`. But that slug is overridden using the specified
`slug` in the front-matter: `this-is-how-i-want-to-name-this-link`.
9 changes: 9 additions & 0 deletions test/site/content/posts/type-and-layout-front-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
+++
title = "Type + Layout Front-matter"
layout = "alternate-single"
tags = ["front-matter", "type", "layout"]
type = "type-test"
draft = false
+++

Here both `type` **and** `layout` are overridden.
13 changes: 13 additions & 0 deletions test/site/content/posts/type-front-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
+++
title = "Type Front-matter"
tags = ["front-matter", "type"]
type = "type-test"
draft = false
+++

The `type` front-matter is used to override the default **section** type
(automatically derived from the directory of the content page).

Here the type is overridden to be `type-test`.

[Reference](https://gohugo.io/content-management/front-matter/#predefined)
13 changes: 13 additions & 0 deletions test/site/content/posts/url-front-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
+++
title = "URL Front-matter"
tags = ["front-matter", "url"]
url = "foo/bar/zoo/url-front-matter"
draft = false
+++

The `url` front-matter is used to specify **the full path to the
content from the web root**. It makes no assumptions about the path of
the content file. It also ignores any language prefixes of the
multilingual feature.

[Reference](https://gohugo.io/content-management/front-matter/#predefined)
13 changes: 13 additions & 0 deletions test/site/layouts/_default/alternate-single.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{ define "main" }}

{{ "**This is `alternate-single` layout from `_default`.**" | markdownify }}

<hr>
{{ .Content }}

<hr>
<a id="debug"></a>
<h3 id="page-debug">Page Params (Debug)</h3>
{{ partial "debugprint.html" .Params }}

{{ end }}
13 changes: 13 additions & 0 deletions test/site/layouts/type-test/alternate-single.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{ define "main" }}

{{ "**This is `alternate-single` layout from type `type-test`.**" | markdownify }}

<hr>
{{ .Content }}

<hr>
<a id="debug"></a>
<h3 id="page-debug">Page Params (Debug)</h3>
{{ partial "debugprint.html" .Params }}

{{ end }}
13 changes: 13 additions & 0 deletions test/site/layouts/type-test/single.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{ define "main" }}

{{ "**This is `single` layout of type `type-test`.**" | markdownify }}

<hr>
{{ .Content }}

<hr>
<a id="debug"></a>
<h3 id="page-debug">Page Params (Debug)</h3>
{{ partial "debugprint.html" .Params }}

{{ end }}

0 comments on commit 79616a3

Please sign in to comment.