Skip to content

Instantly share code, notes, and snippets.

@JonathanDoughty
JonathanDoughty / seo-visual-art-schema.html
Last active January 30, 2019 02:03
Hugo partial to generate VisualArtwork structured data
{{/* layouts/partials/seo-visual-art-schema.html */}}
<script type="application/ld+json">
{
"@context" : "http://schema.org",
"@type" : "VisualArtwork",
"name" : "{{ .Title }}",
"headline" : "{{ .Title }}",{{/* Include the whole content but, using funky regex, do case insensitive replacement of redundant appearances of (near) title */}}
"description" : "{{ replaceRE (printf "(?i) %s " .Title ) " " ( htmlUnescape ( delimit .PlainWords " ") | plainify ) }}",
"material" : "fabric",
"artMedium": "fabric",
@JonathanDoughty
JonathanDoughty / image.html
Last active January 4, 2019 01:40
Hugo shortcode to create / reference responsive images
{{/* Adapted from https://gist.github.com/randallmlough/98c9c949b25f2a41259029e03dd037f3 */}}
{{/* trim leading slash left over from old references */}}
{{- $image := (path.Join "images" (.Get "src")) -}}
{{- $media := (.Site.GetPage "page" "media").Resources -}}
{{- $original := index ($media.Match (printf "%s" $image)) 0 -}}
{{- $class := .Get "class" -}}
{{- $link := .Get "link" -}}
{{- $caption := .Get "caption" -}}
{{- $title := .Get "title" -}}
{{- $alt := .Get "alt" -}}
@JonathanDoughty
JonathanDoughty / background-img.html
Last active January 1, 2022 13:00
Hugo partial for header background image ala gohugo-theme-ananke
{{- $image := replaceRE "^https?://[^/]+/(.*)" "$1" ($.Scratch.Get "image") -}}
{{- $media := (.Site.GetPage "page" "media").Resources -}}
{{- $original := index ($media.Match (printf "%s" $image)) 0 -}}
{{- $width := $original.Width -}}
{{- $intWidth := int $width -}}
{{- $sizes := (sort ($.Param "sizes") "value" ) -}}
{{- $options := $.Param "header_options" -}}
{{- $first := index (first 1 $sizes) 0 -}}
{{- $last := index (last 1 $sizes) 0 -}}
{{- $debug := false -}}
@JonathanDoughty
JonathanDoughty / img-srcset.html
Last active September 5, 2019 17:23
Hugo partial for generating <picture> with responsive image
{{/* Adapted from https://gist.github.com/randallmlough/98c9c949b25f2a41259029e03dd037f3 */}}
{{- $image := replaceRE "^https?://[^/]+/(.*)" "$1" ($.Scratch.Get "image") -}}
{{- $media := (.Site.GetPage "page" "media").Resources -}}
{{- $original := index ($media.Match (printf "%s" $image)) 0 -}}
{{- $width := $original.Width -}}
{{- $intWidth := int $width -}}
{{- $sizes := $.Param "sizes" -}}
{{- $options := $.Param "options" -}}
{{- $usePicture := false -}}{{/* true: Use picture element with source definitions */}}
{{- $multipleSizes := true -}}{{/* true: Provide multiple img sizes attribute */}}