This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{ dateFormat .Site.Params.DateForm (default .Date (.PublishDate)) }} | |
<!-- Above is the optimized version of below, thanks to https://discuss.gohugo.io/t/how-to-use-the-publishdate-if-both-publishdate-and-date-are-set-in-frontmatter/5142/3?u=kaushalmodi --> | |
{{/* with .PublishDate */}} | |
{{/* if eq ($.PublishDate.Format "2006-01-02") "0001-01-01" */}} | |
<!-- Print the Date instead of PublishDate if PublishDate is defined but at its initial value of Jan 1, 0001 --> | |
{{/* $.Date.Format $.Site.Params.DateForm */}} | |
{{/* else */}} | |
{{/* $.PublishDate.Format $.Site.Params.DateForm */}} | |
{{/* end */}} | |
{{/* end */}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{ printf "%#v" . }} | |
If you ever need to drill into what is passed to a template, just put this at the top of your template somewhere: | |
{{ printf "%#v" . }} | |
Then look at a page generated by that template - that'll print out what the top level object is, and what it's fields are. When I do it with a shortcode template, I get something like this: | |
&hugolib.ShortcodeWithPage{Params:[]string{"."}, Inner:"", Page:(*hugolib.Page)(0xc2082e4840)} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Go's reference time for layouts is: | |
Mon Jan 2 15:04:05 MST 2006 | |
which can also be expressed as: | |
01/02 03:04:05PM '06 -0700 | |
For more information: http://golang.org/pkg/time/#pkg-constants535 | |
By picking a default date, there is less parsing that needs to happen, plus they chose a date that shows definitively how to handle things like leading zeroes, day/month ordering and other edge cases that aren't discernible from all dates. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.Site.Pages = All the Pages (note the capital P) in the site. | |
.Data.Pages: All the Pages for the given Node (sections, taxonomies). This will be a subset of the above for all other nodes than the home page: On that Node I believe these slices are the same. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{ define "main" }} | |
{{ $.Scratch.Add "boxClasses" "dt flex center pt0 pb3 pv3-m pv3-ns" }} | |
{{ $.Scratch.Add "boxCopyClasses" "db dtc-ns v-mid w-100 w-75-ns" }} | |
{{ $.Scratch.Add "boxImageClasses" "db dtc-ns v-mid-ns w-25" }} | |
{{ $.Scratch.Add "ImageClasses" "w-100" }} | |
<main class="cf pa3 pa4-m pa5-l mw9 w-60-l center"> | |
<h2> | |
{{ .Title }} | |
</h2> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{ range first 3 (where (where .Site.Pages.ByDate.Reverse "Section" "posts") ".Title" "!=" .Title) }} | |
<!-- latest posts --> | |
{{ end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//control widows, ala www.css-tricks.com/preventing-widows-in-post-titles/ | |
$("ID").each(function() { | |
var wordArray = $(this).text().split(" "); | |
if (wordArray.length > 1) { | |
wordArray[wordArray.length-2] += " " + wordArray[wordArray.length-1]; | |
wordArray.pop(); | |
$(this).html(wordArray.join(" ")); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- code --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% assign events = "" | split: "|" %} | |
{% for item in site.posts %} | |
{% assign current_date = site.time | date: "%Y%m%d" %} | |
{% assign postdate = item.date | date: "%Y%m%d" %} | |
{% if postdate > current_date %} | |
{% assign events = events | push: item %} | |
{% endif %} | |
{% endfor %} |