Skip to content

Instantly share code, notes, and snippets.

View johnfmorton's full-sized avatar
⌨️
Making stuff

John F Morton johnfmorton

⌨️
Making stuff
View GitHub Profile
@johnfmorton
johnfmorton / generate-critical-css.mjs
Created June 8, 2026 15:53
Script used to create Critical CSS with Vite and Craft CMS
#!/usr/bin/env node
/**
* Critical CSS Generator using Beasties
*
* This script fetches HTML from configured URLs and extracts critical CSS
* using Beasties (a pure Node.js solution, no browser required).
*
* Usage:
* node scripts/generate-critical-css.mjs
@johnfmorton
johnfmorton / gist:b8c68455ac7644737d2c4d9d105207fd
Created June 7, 2026 13:32
SETUP_BEASTIES_CRITICAL_CSS.md
# Set up Beasties Critical CSS on this Craft + Vite project
You are an AI coding agent (Claude Code, Codex, Cursor, etc.) being asked to add Beasties-based Critical CSS generation to the Craft CMS + Vite repository you are currently running inside.
**Do not start changing files immediately.** This guide is interactive. You must first inspect the repository, then ask the developer the questions in the "Confirm With the Developer" section, then make the changes. If something does not match the assumptions in this document, surface it and ask before doing anything destructive.
Your goal at the end of this process:
1. Beasties generates one critical CSS file per unique template layout.
2. The files are written to `web/dist/criticalcss/` (or the project's equivalent webroot path).
@johnfmorton
johnfmorton / .zshrc
Last active April 7, 2026 17:10
A zsh function for chatting with local Gemma 4 via Ollama — streaming output, Glow markdown rendering, conversation history, and @filename / PDF support.
# the following function goes in your .zshrc file to add "gemma" to your command line
# see https://supergeekery.ddev.site/blog/running-googles-gemma-4-locally-on-macos-with-ollama
# and https://supergeekery.com/blog/upgrading-your-local-gemma-setup
# for more details
gemma() {
setopt local_options no_monitor no_notify
if ! curl -sf http://localhost:11434/ > /dev/null 2>&1; then
echo "Starting Ollama service..."
brew services start ollama
while ! curl -sf http://localhost:11434/ > /dev/null 2>&1; do
@johnfmorton
johnfmorton / warm_cache.sh
Created February 1, 2025 16:40
Bash script to warm the cache on a website with the sitemap.xml. I use it to warm my FastCGI cache via a nightly cron job.
#!/bin/bash
# Usage: ./warm_cache.sh [SITEMAP_INDEX_URL] [DELAY_SECONDS]
# Example: ./warm_cache.sh "https://example.com/sitemap.xml" 1
#
# If no sitemap index URL is provided, a default is used.
DEFAULT_SITEMAP_INDEX_URL="https://example.com/sitemap.xml"
SITEMAP_INDEX_URL="${1:-$DEFAULT_SITEMAP_INDEX_URL}"
# Delay (in seconds) between each request. Default is 0 seconds if not provided.
DELAY="${2:-0}"
@johnfmorton
johnfmorton / squarespace-hover-image-alt-tag.html
Last active October 1, 2024 17:07
Squarespace snippet - add to a page via "Page Header Code Injection" to add rollover of alt text to img with links
/*
* Add hover effect showing alt tag of images
* with Squarespace 7.1 fluid image containers
* John F Morton - https://supergeekery.com
*/
<script>
document.addEventListener('DOMContentLoaded', function() {
const imageContainers = document.querySelectorAll('.fluid-image-container.sqs-image-content')
@johnfmorton
johnfmorton / config.applesilicon.yaml
Last active July 25, 2024 20:51
DDEV config file to add chromium to an Apple Silicon machine. Useful when creating Critical CSS. See: https://nystudio107.com/docs/vite/#using-ddev
webimage_extra_packages:
[
gconf-service,
libasound2,
libatk1.0-0,
libcairo2,
libgconf-2-4,
libgdk-pixbuf2.0-0,
libgtk-3-0,
libnspr4,
@johnfmorton
johnfmorton / video-allowed-htmlpurifier.json
Last active April 3, 2025 10:48
Sample HTMLPurifier config to allow YouTube and Vimeo embeds - used with CKEditor in Craft CMS
{
"HTML.SafeIframe": true,
"URI.SafeIframeRegexp": "%^(https?:)?//(www.youtube.com/|youtube.com/|youtu.be/|player.vimeo.com/)%"
}
@johnfmorton
johnfmorton / ck-editor-video-embed-youtube.ts
Last active October 21, 2025 16:10
Sample Typescript used in conjunction with CKEditor to convert video embeds into video tags on frontend
document.addEventListener('DOMContentLoaded', (event) => {
// Find all oembed elements
const oembedElements = document.querySelectorAll('oembed[url]');
oembedElements.forEach(element => {
const url = element.getAttribute('url');
let videoId: string | null;
if (!url) return;
videoId = extractYouTubeId(url);
@johnfmorton
johnfmorton / standard-plus-ck-editor-config.json
Last active August 5, 2024 09:30
CKEditor config with helpful additions - custom fonts, an addition font size example, and open links in new window option
{
"alignment": {
"options": [
"left",
"center",
"right"
]
},
"code": {
"indentSequence": " "
@johnfmorton
johnfmorton / gist:639451fea75d84a5b89b5bcacb6ae8bb
Created May 16, 2024 17:52
Example script to get a YouTube video to display on a page that has an embed
<script>
document.addEventListener('DOMContentLoaded', (event) => {
// Find all oembed elements
const oembedElements = document.querySelectorAll('oembed[url]');
oembedElements.forEach(element => {
const url = element.getAttribute('url');
const videoId = extractYouTubeId(url);
if (videoId) {