Skip to content

Instantly share code, notes, and snippets.

View MWDelaney's full-sized avatar

Michael W. Delaney MWDelaney

View GitHub Profile
@MWDelaney
MWDelaney / page.njk
Created August 11, 2022 01:40
Using a single Eleventy template to create multiple versions of a page
---
eleventyExcludeFromCollections: true
pagination:
data: collections.versions
size: 1
alias: page
eleventyComputed:
title: "{{ page.data.title }}"
permalink: "/{{ page.data.version | slugify }}/{{ page.data.title | slugify }}/"
---
@MWDelaney
MWDelaney / store-admin-config.njk
Last active May 27, 2022 14:36
Create separate, stripped-down NetlifyCMS editors for stores in an Eleventy collection
---
eleventyExcludeFromCollections: true
pagination:
data: collections.stores
size: 1
alias: store
eleventyComputed:
title: "{{ store.data.title }} Content Manager config"
permalink: "/stores/{{ store.data.slugOverride | slugify }}/admin/config.yml"
---
@MWDelaney
MWDelaney / timeAgo.js
Last active May 12, 2022 21:45
Eleventy-friendly "time ago" javascript snippet.
/**
* "Time Ago" vanilla javascript snippet
*
* Lovingly stolen from StackOverflow here: https://stackoverflow.com/a/37802747
*
* Convert elements like this:
* <time datetime="Thu May 12 2022 21:05:56 GMT+0000 (Coordinated Universal Time)">May 12th, 2022</time>
*
* To This:
* <time datetime="Thu May 12 2022 21:05:56 GMT+0000 (Coordinated Universal Time)">4 days ago</time>
@MWDelaney
MWDelaney / .eleventy.js
Last active April 21, 2024 08:49
Tag-friendly pagination for Eleventy
...
postsByTag: function (eleventyConfig) {
let _ = require("lodash");
eleventyConfig.addCollection("postsByTag", function(collection) {
// Get unique list of tags
let tagSet = new Set();
collection.getAllSorted().map(function(item) {
if( "tags" in item.data ) {
@MWDelaney
MWDelaney / .eleventy.js
Last active January 2, 2023 08:33 — forked from freshyill/.eleventy.js
YouTube Editor component for Netlify CMS
eleventyConfig.addNunjucksShortcode("youtube", function (youtubeId, aspectRatio) {
return `<div class="aspect-ratio" style="--aspect-ratio: ${aspectRatio}"><iframe class="youtube-player video video--youtube" src="https://www.youtube.com/embed/${youtubeId}/" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></div>`;
});
@MWDelaney
MWDelaney / facetwp-bootstrap-checkboxes.php
Last active November 30, 2021 16:33
Replace FacetWP checkboxes with Bootstrap custom checkbox markup.
<?php
/**
* Replace FacetWP default HTML output for "Checkboxes" with Bootstrap custom checkbox markup
*/
add_filter('facetwp_facet_html', function ($output, $params) {
// Check that this facet is a "checkboxes" type facet before proceeding.
if ('checkboxes' == $params['facet']['type']) {
// Initialize variables
@MWDelaney
MWDelaney / app.js
Last active March 26, 2023 20:32
Gravity Forms better spinner
$(".gform_wrapper form").on("submit", function(e){
$(this).find(".gform_button").attr("disabled", true);
});
@MWDelaney
MWDelaney / the-events-calendar-automatic-ticket-categories.php
Created June 20, 2019 14:35
Automatically apply "tribe_events_cat" taxonomy terms to WooCommerce tickets when tickets are saved or updated.
<?php
// Apply product categories to newly created or saved tickets that match the The Events Calendar categories of the associated event
add_action('event_tickets_after_save_ticket', function ($event_id, $ticket, $raw_data, $classname) {
if (! empty($ticket) && isset($ticket->ID)) {
// Apply the "event-tickets" category to add tickets so that all tickets have at least this category to start
wp_add_object_terms($ticket->ID, 'event-tickets', 'product_cat');
// Get all the other "tribe_events_cat" taxonomy terms on the event
@MWDelaney
MWDelaney / facetwp.php
Last active March 12, 2019 17:38
Rewrite the HTML output of radio buttons into a Bootstrap dropdown
<?php
// Adjust FacetWP "Radio" HTML output to be friendlier with our theme
add_filter('facetwp_facet_html', function ($output, $params) {
// Check that this facet is a "radio" type facet before proceeding.
if ('radio' == $params['facet']['type']) {
// Initialize our variables
$output = '';