diff --git a/ox-hugo.el b/ox-hugo.el index 8e2910b..a8117b0 100644 --- a/ox-hugo.el +++ b/ox-hugo.el @@ -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 @@ -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) diff --git a/test/site/content-org/all-posts.org b/test/site/content-org/all-posts.org index 383fda0..4e0efe3 100644 --- a/test/site/content-org/all-posts.org +++ b/test/site/content-org/all-posts.org @@ -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: diff --git a/test/site/content/posts/output-empty.md b/test/site/content/posts/output-empty.md new file mode 100644 index 0000000..7c3d004 --- /dev/null +++ b/test/site/content/posts/output-empty.md @@ -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). diff --git a/test/site/content/posts/output-html-and-json.md b/test/site/content/posts/output-html-and-json.md new file mode 100644 index 0000000..277b87c --- /dev/null +++ b/test/site/content/posts/output-html-and-json.md @@ -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). diff --git a/test/site/themes/bare_min/layouts/_default/single.json b/test/site/themes/bare_min/layouts/_default/single.json new file mode 100644 index 0000000..bb958f5 --- /dev/null +++ b/test/site/themes/bare_min/layouts/_default/single.json @@ -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 }}" +} diff --git a/test/site/themes/bare_min/layouts/partials/debugprint.html b/test/site/themes/bare_min/layouts/partials/debugprint.html index 9d46fd4..6b76acc 100644 --- a/test/site/themes/bare_min/layouts/partials/debugprint.html +++ b/test/site/themes/bare_min/layouts/partials/debugprint.html @@ -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) }} -{{ $typeIsMap := (findRE "^(map[[].+[]]|.*SiteSocial)" $type) }} +{{ $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) }} +{{ $typeIsMap := (findRE "^(map[[].+[]]|.*SiteSocial)" $type) }} -{{ $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 "%#v" $value $value | safeHTML }} @@ -93,6 +94,17 @@ {{ printf "" | safeHTML }} {{ end }} + {{ 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 ) }} + + + {{ range $idx, $elem := $OutputFormatVarNames }} + {{ printf "" | safeHTML }} + {{ end }} +
OutputFormat VariableValue
%s" $elem | safeHTML }} + {{ partial "debugprint.html" (index $OutputFormatVarSymbols $idx) }} + {{ printf "
{{ else }} {{ printf "%#v" $value | safeHTML }} {{ end }}