Skip to content

Instantly share code, notes, and snippets.

View budparr's full-sized avatar
🎯
Focusing

Bud Parr budparr

🎯
Focusing
View GitHub Profile
@budparr
budparr / jekyll-group_by-example.liquid
Last active January 21, 2024 11:10
Example Jekyll group_by filter #jekyllrb
{% comment %}
items is a collection, though I think it coule be any content type
{% endcomment %}
{% comment %} Create the group. {% endcomment %}
{% assign items_grouped = site.items | group_by: 'category' | sort: 'name' | reverse %}
{% comment %}
The above returns, for example, which is why we sort by 'name'
{"name"=>"category1_value", "items"=>[#, #, #, #, #]}{"name"=>"category2_value", "items"=>[#, #, #, #]}
{% endcomment %}
@budparr
budparr / hugo-airtable.html
Created April 14, 2019 18:54
Fooling around with incorporating Airtable data into a Hugo site using getJSON. Started with some code from https://github.com/colinbate/for-sale/ and first just wanted to pull in data from another table.
{{ $apiPrefix := "https://api.airtable.com/v0/"}}
{{ $key := getenv "AIRTABLE_KEY" }}
{{ if isset .Site.Params "view" }}
{{ .Scratch.Set "view" (printf "&view=%s" .Site.Params.view) }}
{{ else }}
{{ .Scratch.Set "view" "" }}
{{ end }}
{{ if isset .Site.Params "speakers_view" }}
@budparr
budparr / jekyll-collections-prev-next.html
Last active September 29, 2021 10:55
Previous Next Links for Jekyll Collections
{% capture the_collection %}{{page.collection}}{% endcapture %}
{% if page.collection %}
{% assign document = site[the_collection] %}
{% endif %}
<h1>TITLE: {{ page.title }}</h1>
{% for links in document %}
{% if links.title == page.title %}
{% unless forloop.first %}
{% assign prevurl = prev.url %}
{% endunless %}
@budparr
budparr / hugo-multiple-where-statmenets.html
Last active May 6, 2021 14:12
multiple where statements Remember that Hugo uses parameters in the range statement from the inside out. Order matters.
{{ range first 3 (where (where .Site.Pages.ByDate.Reverse "Section" "posts") ".Title" "!=" .Title) }}
<!-- latest posts -->
{{ end }}
@budparr
budparr / split.sh
Created February 15, 2021 18:33 — forked from arthurattwell/split.sh
Split a markdown file into separate files on YAML frontmatter
#!/bin/bash
# That tells Linux to use a Bourne shell interpreter.
# Run this script from the current directory. (Required on OSX.)
cd -- "$(dirname "$0")"
# Don't echo these commands.
set +v
# Get the filename from the user.
{{ $url := replace .Permalink ( printf "%s" .Site.BaseURL) "" }}
{{ $.Scratch.Add "path" .Site.BaseURL }}
<ol class="breadcrumbs">
<li><a href="/">home</a></li>
{{ range $index, $element := split $url "/" }}
{{ $.Scratch.Add "path" $element }}
{{ if ne $element "" }}
<li><a href='{{ $.Scratch.Get "path" }}'>{{ . }}</a></li>
{{ $.Scratch.Add "path" "/" }}
{{ end }}
@budparr
budparr / figure.html
Last active September 23, 2020 15:39
Hugo "figure" shortcode that works with https://github.com/aFarkas/lazysizes and uses `markdownify` for title and caption #gohugo
<!-- 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" }}
@budparr
budparr / robots.txt
Last active August 13, 2019 14:21
Jekyll Robots page to exclude from robots pages that are excluded from the sitemap
---
layout: null
permalink: robots.txt
---
# filter pages and documents for the noindex key
{% assign noindexPages = site.pages | where: 'sitemap', false %}
{% assign noindexDocuments = site.documents | where: 'sitemap', false %}
User-agent: *
# robotstxt.org - if _config production variable is false robots will be disallowed.
{% if site.production != true %}
@budparr
budparr / dynamic-html-lambda.js
Created January 26, 2019 17:50 — forked from DavidWells/dynamic-html-lambda.js
Respond with dynamic HTML from a lambda function
module.exports = (event, context, callback) => {
let name
if (event.pathParameters && event.pathParameters.name) {
name = event.pathParameters.name
}
/* generate the hello paragraph */
const helloParagraph = greetPerson(name)
// callback is sending HTML back