Update default archetype

Update the default archetype to specify all relevant frontmatter fields.
Updated the bigimg and comments features to handle "unset" or "null"
values in the frontmatter and default appropriately. Also updated the
bigimg sample to explain both the default and "flow" YAML syntax.
This commit is contained in:
Michael Romero 2017-03-07 02:53:09 -08:00
parent 0c37d7b395
commit ba07f7cc67
7 changed files with 32 additions and 19 deletions

View File

@ -1,6 +1,6 @@
+++ ---
title = "" subtitle: ""
subtitle = "" comments:
date = "2014-07-11T10:54:24+02:00" tags: []
bigimg = "" bigimg: [{}]
+++ ---

View File

@ -17,10 +17,24 @@ bigimg: [{src: "/img/triangle.jpg", desc: "Triangle"}]
Multiple bigimgs can be specified in the front matter by the following YAML: Multiple bigimgs can be specified in the front matter by the following YAML:
``` ```
bigimg: [{src: "/img/triangle.jpg", desc: "Triangle"}, {src: "/img/sphere.jpg", desc: "Sphere"}, {src: "/img/hexagon.jpg", desc: "Hexagon"}] bigimg: [{src: "/img/triangle.jpg", desc: "Triangle"},
{src: "/img/sphere.jpg", desc: "Sphere"},
{src: "/img/hexagon.jpg", desc: "Hexagon"}]
``` ```
Also note that the description field is optional, and images could instead be specified by: Also note that the description field is optional, and images could instead be specified by:
``` ```
bigimg: [{src: "/img/triangle.jpg"}, {src: "/img/sphere.jpg"}, {src: "/img/hexagon.jpg"}] bigimg: [{src: "/img/triangle.jpg"},
{src: "/img/sphere.jpg"},
{src: "/img/hexagon.jpg"}]
``` ```
The above YAML array of hashes were written in "flow" style. However when generating a new page or post with `hugo new post/mypost.md`, hugo may interpret the archetype for bigimg in the default YAML style. Defining multiple bigimg's complete with descriptions in this style would be specified by:
```
bigimg:
- {src: "/img/triangle.jpg", desc: "Triangle"}
- {src: "/img/sphere.jpg", desc: "Sphere"}
- {src: "/img/hexagon.jpg", desc: "Hexagon"}
```
Additional information can be found [in this YAML tutorial](https://rhnh.net/2011/01/31/yaml-tutorial/).

View File

@ -7,12 +7,12 @@
{{ partial "nav.html" . }} {{ partial "nav.html" . }}
{{ if .Site.Params.bigimg }} {{ if isset .Site.Params.bigimg 1 }}
<div id="header-big-imgs" data-num-img={{len .Site.Params.bigimg}} {{range $i, $img := .Site.Params.bigimg}}data-img-src-{{add $i 1}}="{{$img.src}}" data-img-desc-{{add $i 1}}="{{$img.desc}}"{{end}}></div> <div id="header-big-imgs" data-num-img={{len .Site.Params.bigimg}} {{range $i, $img := .Site.Params.bigimg}}data-img-src-{{add $i 1}}="{{$img.src}}" data-img-desc-{{add $i 1}}="{{$img.desc}}"{{end}}></div>
{{ end }} {{ end }}
<header class="header-section {{ if .Site.Params.bigimg }}has-img{{ end }}"> <header class="header-section {{ if isset .Site.Params.bigimg 1 }}has-img{{ end }}">
<div class="intro-header {{ if .Site.Params.bigimg }}big-img{{ else }}no-img{{ end }}"> <div class="intro-header {{ if isset .Site.Params.bigimg 1 }}big-img{{ else }}no-img{{ end }}">
<div class="container"> <div class="container">
<div class="row"> <div class="row">
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1"> <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">

View File

@ -1,4 +1,4 @@
{{ if (.Params.comments) | or (and (not (isset .Params "comments")) (.Site.Params.comments)) }} {{ if (.Params.comments) | or (and (or (not (isset .Params "comments")) (eq .Params.comments nil)) (.Site.Params.comments)) }}
{{ if .Site.DisqusShortname }} {{ if .Site.DisqusShortname }}
<div class="comments"> <div class="comments">
{{ template "_internal/disqus.html" . }} {{ template "_internal/disqus.html" . }}

View File

@ -1,11 +1,10 @@
{{ if or .Params.bigimg .Title }} {{ if or .Params.bigimg .Title }}
{{ if isset .Params.bigimg 1 }}
{{ if .Params.bigimg }}
<div id="header-big-imgs" data-num-img={{len .Params.bigimg}} {{range $i, $img := .Params.bigimg}}data-img-src-{{add $i 1}}="{{$img.src}}" {{ if $img.desc}}data-img-desc-{{add $i 1}}="{{$img.desc}}"{{end}}{{end}}></div> <div id="header-big-imgs" data-num-img={{len .Params.bigimg}} {{range $i, $img := .Params.bigimg}}data-img-src-{{add $i 1}}="{{$img.src}}" {{ if $img.desc}}data-img-desc-{{add $i 1}}="{{$img.desc}}"{{end}}{{end}}></div>
{{ end }} {{ end }}
<header class="header-section {{ if .Params.bigimg }}has-img{{ end }}"> <header class="header-section {{ if isset .Params.bigimg 1 }}has-img{{ end }}">
<div class="intro-header {{ if .Params.bigimg }}big-img{{ else }}no-img{{ end }}"> <div class="intro-header {{ if isset .Params.bigimg 1 }}big-img{{ else }}no-img{{ end }}">
{{ partial "header.html" . }} {{ partial "header.html" . }}
<span class="img-desc" style="display: inline;"></span> <span class="img-desc" style="display: inline;"></span>
</div> </div>

View File

@ -2,7 +2,7 @@
<div class="row"> <div class="row">
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1"> <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
{{ .Content }} {{ .Content }}
{{ if (.Params.comments) | or (and (not (isset .Params "comments")) (.Site.Params.comments)) }} {{ if (.Params.comments) | or (and (or (not (isset .Params "comments")) (eq .Params.comments nil)) (.Site.Params.comments)) }}
{{ if .Site.DisqusShortname }} {{ if .Site.DisqusShortname }}
<div class="disqus-comments"> <div class="disqus-comments">
{{ template "_internal/disqus.html" . }} {{ template "_internal/disqus.html" . }}

View File

@ -18,7 +18,7 @@
{{ end }} {{ end }}
</ul> </ul>
{{ if (.Params.comments) | or (and (not (isset .Params "comments")) (.Site.Params.comments)) }} {{ if (.Params.comments) | or (and (or (not (isset .Params "comments")) (eq .Params.comments nil)) (.Site.Params.comments)) }}
{{ if .Site.DisqusShortname }} {{ if .Site.DisqusShortname }}
<div class="disqus-comments"> <div class="disqus-comments">
{{ template "_internal/disqus.html" . }} {{ template "_internal/disqus.html" . }}