Skip to content

Instantly share code, notes, and snippets.

View jensgro's full-sized avatar

Jens Grochtdreis jensgro

View GitHub Profile
@jensgro
jensgro / 11ty_contains.js
Created February 9, 2023 22:19 — forked from danfascia/11ty_contains.js
11ty filter to filter a collection (array) by key:value pair - used to filter on custom taxonomies other than tags (source: https://paulrobertlloyd.com/)
/**
* Select objects in array whose key includes a value
*
* @param {Array} arr Array to test
* @param {String} key Key to inspect
* @param {String} value Value key needs to include
* @return {String} Filtered array
*
*/
module.exports = function (arr, key, value) {
@jensgro
jensgro / 11ty_is.js
Created February 9, 2023 22:19 — forked from danfascia/11ty_is.js
11ty filter to filter items in a collection (array) whose key === value. (source: https://paulrobertlloyd.com/)
/**
* Select objects in array whose key matches a value
*
* @param {Array} arr Array to test
* @param {String} key Key to inspect
* @param {String} value Value key needs to match
* @return {String} Filtered array
*
*/
module.exports = function (arr, key, value) {
@jensgro
jensgro / 11ty_permalink.js
Created February 9, 2023 22:19 — forked from danfascia/11ty_permalink.js
Removes index.html from 11ty URL strings to create prettier permalinks. Usage {{url | permalink}} (source: https://paulrobertlloyd.com/)
@jensgro
jensgro / 11ty_date.js
Created February 9, 2023 22:19 — forked from danfascia/11ty_date.js
11ty Date formatting filter using Luxon. Usage: {{ date_field | date('dd LLLL yyyy') }}
const { DateTime } = require("luxon");
// date filter formatting using Luxon. Usage: {{ date_field | date('dd LLLL yyyy') }}
eleventyConfig.addFilter("date", (it, format = "LLLL dd, yyyy") => {
return DateTime.fromJSDate(it, { zone: "utc" }).toFormat(format);
});
@jensgro
jensgro / 11ty_is-not.js
Created February 9, 2023 22:19 — forked from danfascia/11ty_is-not.js
11ty filter to remove items from a filtered array by key:value pair - i.e. {% collection_array... | is-not: 'url', page.url %} (source: https://paulrobertlloyd.com/)
/**
* Remove objects in array whose key matches a value
*
* @param {Array} arr Array to test
* @param {String} key Key to inspect
* @param {String} value Value key needs to match
* @return {String} Filtered array
*
*/
module.exports = function (arr, key, value) {
@jensgro
jensgro / 11ty_excerpts.js
Created February 9, 2023 22:18 — forked from danfascia/11ty_excerpts.js
11ty filter to split a string {{content}} into an excerpt (i.e. all stuff before <!--more-->) and the remainder (i.e. stuff after that tag...). Source: https://hawksworx.com
/**
* Split the content into excerpt and remainder
*
* @param {String} str
* @param {String [excerpt | remainder]} section
*
* If excerpt or nothing is passed as an argument, we return what was before the split marker.
* If remainder is passed as an argument, we return the rest of the post
*
*/
@jensgro
jensgro / animated-underline-link.css
Created February 9, 2023 22:18 — forked from danfascia/animated-underline-link.css
Animated underline from left to right on links
@jensgro
jensgro / toggleFullScreen.js
Created February 9, 2023 22:18 — forked from danfascia/toggleFullScreen.js
Toggle fullscreen javascript
function toggleFullScreen() {
if ((document.fullScreenElement && document.fullScreenElement !== null) ||
(!document.mozFullScreen && !document.webkitIsFullScreen)) {
if (document.documentElement.requestFullScreen) {
document.documentElement.requestFullScreen();
} else if (document.documentElement.mozRequestFullScreen) {
document.documentElement.mozRequestFullScreen();
} else if (document.documentElement.webkitRequestFullScreen) {
document.documentElement.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
}
@jensgro
jensgro / 11ty_getTagList.js
Created February 9, 2023 22:18 — forked from danfascia/11ty_getTagList.js
Used in config to create a collection (tagList) of tag names which can be iterated.
/*
Usage:
eleventyConfig.addCollection("tagList", require("11ty_getTagList.js") );
This collection then produces a useful list...
for tag in collections.tagList...
which then gives access to
// Stolen from https://stackoverflow.com/a/31615643
const appendSuffix = n => {
var s = ['th', 'st', 'nd', 'rd'],
v = n % 100;
return n + (s[(v - 20) % 10] || s[v] || s[0]);
};
module.exports = function dateFilter(value) {
const dateObject = new Date(value);