Instantly share code, notes, and snippets.

View hugo-search-index.json
{{- $.Scratch.Add "index" slice -}}
{{$index := where .Site.RegularPages ".Section" "not in" (slice "links" "internal") }}
{{- range $index -}}
{{ with .Params.images }}
{{ $.Scratch.Set "image" (index . 0)}}
{{ else }}
{{ $.Scratch.Set "image" "/uploads/logo.jpg"}}
{{ end }}
{{ $image := printf "%s%s" (replace ($.Scratch.Get "image") "/uploads" .Site.Params.image_url) "?fit=crop&h=201&w=358" }}
{{- $content_filtered := replaceRE "(?m)(?i)(?s:\\ba\\b|\\band\\b|\\barchival\\b|\\bagain\\b|\\bin\\b|\\bto\\b|\\bis\\b|\\bno\\b|\\bor\\b|\\bthis\\b|\\bwell\\b|\\byes\\b|\\bthe\\b|\\bthere\\b|\\bthese\\b|\\bthen\\b)" "" (delimit .PlainWords " ") -}}
View awebpackfile.js
const path = require("path");
const UglifyJSPlugin = require("uglifyjs-webpack-plugin");
const CleanWebpackPlugin = require("clean-webpack-plugin");
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const PurgecssPlugin = require("purgecss-webpack-plugin");
const glob = require("glob-all");
const webpack = require("webpack");
//let toProvide = {}
View figure.html
<!-- image -->
<figure {{ with .Get "class" }}class="{{.}}"{{ end }}>
{{ with .Get "link"}}<a href="{{.}}">{{ end }}
<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-src="{{ .Get "src" }}" {{ if or (.Get "alt") (.Get "caption") }}alt="{{ with .Get "alt"}}{{.}}{{else}}{{ .Get "caption" }}{{ end }}" {{ end }}{{ with .Get "width" }}width="{{.}}" {{ end }} class="lazyload" />
<noscript>
<img src="{{ .Get "src" }}" {{ if or (.Get "alt") (.Get "caption") }}alt="{{ with .Get "alt"}}{{.}}{{else}}{{ .Get "caption" }}{{ end }}" {{ end }}{{ with .Get "width" }}width="{{.}}" {{ end }}/>
</noscript>
{{ if .Get "link"}}</a>{{ end }}
{{ if or (or (.Get "title") (.Get "caption")) (.Get "attr")}}
<figcaption>{{ if isset .Params "title" }}
View hugo-set-params
{{/* Set header classes (e.g. colors scheme) at either the global, section, or page level */}}
{{/* Initially set $.Param "headerClasses" at the page or global (config) level, with a default if neither exist */}}
{{ $headerClasses := $.Param "headerClasses" | default "bg-near-black silver"}}
{{/* To set at the section level, get the section the current page belongs to */}}
{{ $section := .Site.GetPage "section" .Section }}
{{/* If the page belongs to a section, */}}
{{ if $section}}
{{/* get the section's headerClasses param value, defaulting to the global/page level. */}}
{{ $headerClasses := $section.Param "headerClasses" | default $headerClasses }}
{{/* Set the colors based on the page's setting, but if there isn't one, look to the section's settings above */}}
View hugo-error.txt
4:15:17 PM: Build started
4:16:31 PM: Fetching cached dependencies
4:16:32 PM: No cached dependencies found. Cloning fresh repo
4:16:32 PM: git clone git@github.com:budparr/gohugo.io
4:16:33 PM: git remote rm origin
4:16:33 PM: Preparing Git Reference refs/heads/master
4:16:35 PM: Building site
4:16:35 PM: Running build command
4:16:36 PM: v6.10.0 is already installed.
4:16:37 PM: Now using node v6.10.0 (npm v3.10.10)
View hugo-env-check
{{ if eq (getenv "HUGO_ENV") "production" }}
<!-- production stuff here -->
{{ end }}
View hugo-date-format
{{ 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 */}}
View hugo-page-data.html
{{ 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)}
View hugo-date-formatting
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.