Skip to content

Commit

Permalink
Make outputs front-matter var a list
Browse files Browse the repository at this point in the history
- Add test for JSON output creation
  - Add single.json in bare_min layouts/_default for this testing purpose
- Update debugprint.html partial to pretty-print the outputs Param
  • Loading branch information
kaushalmodi committed Nov 16, 2017
1 parent 55e3964 commit fd7eb84
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 12 deletions.
6 changes: 5 additions & 1 deletion ox-hugo.el
Original file line number Diff line number Diff line change
Expand Up @@ -1778,6 +1778,10 @@ INFO is a plist used as a communication channel."
(org-string-nw-p (mapconcat #'identity
alias-list
org-hugo--internal-list-separator))))
(outputs-raw (org-string-nw-p
(org-export-data (plist-get info :hugo-outputs) info)))
(outputs (when outputs-raw
(org-split-string outputs-raw " ")))
(lastmod-raw (org-string-nw-p (org-export-data (plist-get info :hugo-lastmod) info)))
(lastmod-nocolon (cond
;; If the set HUGO_LASTMOD is already in
Expand Down Expand Up @@ -1886,7 +1890,7 @@ INFO is a plist used as a communication channel."
(lastmod . ,lastmod)
(linkTitle . ,(org-export-data (plist-get info :hugo-linktitle) info))
(markup . ,(org-export-data (plist-get info :hugo-markup) info))
(outputs . ,(org-export-data (plist-get info :hugo-outputs) info))
(outputs . ,outputs)
(slug . ,(org-export-data (plist-get info :hugo-slug) info))
(tags . ,tags)
(categories . ,categories)
Expand Down
18 changes: 18 additions & 0 deletions test/site/content-org/all-posts.org
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,24 @@ The following results in the 'genres' property having the value
:EXPORT_HUGO_CUSTOM_FRONT_MATTER+: :booleans '(true false)
:END:
[[https://github.com/kaushalmodi/ox-hugo/issues/99][Issue # 99]]
* Outputs :outputs:
** Output HTML and JSON :json:
:PROPERTIES:
:EXPORT_FILE_NAME: output-html-and-json
:EXPORT_HUGO_OUTPUTS: html json
:END:
*Note*: A =single.json= is required to be at a valid location in the
template lookup hierarchy for the JSON outputs to be created.

[[./index.json][Here's the JSON output version of this page]].
** Setting empty outputs is fine :empty:
:PROPERTIES:
:EXPORT_FILE_NAME: output-empty
:EXPORT_HUGO_OUTPUTS:
:END:
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
:PROPERTIES:
Expand Down
9 changes: 9 additions & 0 deletions test/site/content/posts/output-empty.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
+++
title = "Setting empty outputs is fine"
tags = ["outputs", "empty"]
draft = false
+++

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).
11 changes: 11 additions & 0 deletions test/site/content/posts/output-html-and-json.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
+++
title = "Output HTML and JSON"
outputs = ["html", "json"]
tags = ["outputs", "json"]
draft = false
+++

**Note**: A `single.json` is required to be at a valid location in the
template lookup hierarchy for the JSON outputs to be created.

[Here's the JSON output version of this page](./index.json).
7 changes: 7 additions & 0 deletions test/site/themes/bare_min/layouts/_default/single.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"uri": "{{ .Permalink }}",
"title": "{{ .Title | htmlEscape }}",
"tags": [{{ range $tindex, $tag := .Params.tags }}{{ if $tindex }}, {{ end }}"{{ $tag| htmlEscape }}"{{ end }}],
"description": "{{ .Description | htmlEscape }}",
"content": "{{ range $i, $words := .PlainWords }}{{ $words | htmlEscape }} {{ end }}"
}
34 changes: 23 additions & 11 deletions test/site/themes/bare_min/layouts/partials/debugprint.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@
{{/* partial "debugprint.html" .GitInfo */}}
{{/* partial "debugprint.html" (slice "File" .) */}}
-->
{{ $value := . }}
{{ $type := (printf "%T" $value) }}
{{ $typeIsBool := (eq "bool" $type) }}
{{ $typeIsString := (eq "string" $type) }}
{{ $typeIsTime := (eq "time.Time" $type) }}
{{ $typeIsInterface := (eq "interface" $type) }}
{{ $typeIsSlice := (findRE "^([[][]]|.*TaxonomyList)" $type) }} <!-- match ^[] -->
{{ $typeIsMap := (findRE "^(map[[].+[]]|.*SiteSocial)" $type) }} <!-- match ^map[*] -->
{{ $value := . }}
{{ $type := (printf "%T" $value) }}
{{ $typeIsBool := (eq "bool" $type) }}
{{ $typeIsString := (eq "string" $type) }}
{{ $typeIsTime := (eq "time.Time" $type) }}
{{ $typeIsInterface := (eq "interface" $type) }}
{{ $typeIsSlice := (findRE "^([[][]]|.*TaxonomyList|output\\.Formats)" $type) }} <!-- match ^[] -->
{{ $typeIsMap := (findRE "^(map[[].+[]]|.*SiteSocial)" $type) }} <!-- match ^map[*] -->

{{ $typeIsSiteInfo := (eq "*hugolib.SiteInfo" $type) }}
{{ $typeIsGitInfo := (findRE "^.*gitmap\\.GitInfo" $type) }}
{{ $typeIsSpecial := (or $typeIsSiteInfo $typeIsGitInfo) }}
{{ $typeIsSiteInfo := (eq "*hugolib.SiteInfo" $type) }}
{{ $typeIsGitInfo := (findRE "^.*gitmap\\.GitInfo" $type) }}
{{ $typeIsOutputFormat := (eq "output.Format" $type) }}
{{ $typeIsSpecial := (or $typeIsSiteInfo $typeIsGitInfo $typeIsOutputFormat) }}

{{ if $typeIsBool }}
{{ printf "<span class=\"debugprint\"><span class=\"%#v\">%#v</span></span>" $value $value | safeHTML }}
Expand Down Expand Up @@ -93,6 +94,17 @@
{{ printf "</td></tr>" | safeHTML }}
{{ end }}
</table>
{{ else if $typeIsOutputFormat }}
{{ $OutputFormatVarNames := (slice "Name" "MediaType" "Path" "BaseName" "Rel" "Protocol" "IsPlainText" "IsHTML" "NoUgly" "NotAlternative") }}
{{ $OutputFormatVarSymbols := (slice .Name .MediaType .Path .BaseName .Rel .Protocol .IsPlainText .IsHTML .NoUgly .NotAlternative ) }}
<table>
<tr><th class="key">OutputFormat Variable</th><th class="value">Value</th></tr>
{{ range $idx, $elem := $OutputFormatVarNames }}
{{ printf "<tr><td class=\"key\">%s</td><td class=\"value\">" $elem | safeHTML }}
{{ partial "debugprint.html" (index $OutputFormatVarSymbols $idx) }} <!-- Recursive call FTW! -->
{{ printf "</td></tr>" | safeHTML }}
{{ end }}
</table>
{{ else }}
{{ printf "%#v" $value | safeHTML }}
{{ end }}
Expand Down

0 comments on commit fd7eb84

Please sign in to comment.