Skip to content

Instantly share code, notes, and snippets.

@robweychert
robweychert / frame-based-animation.md
Last active September 8, 2021 15:19
A simple Sass function for frame-based CSS animation

A simple Sass function for frame-based CSS animation

If you have experience with animation in other media, CSS animation’s percentage-based keyframe syntax can feel pretty alien, especially if you want to be very precise about timing. This Sass function lets you forget about percentages and express keyframes in terms of actual frames:

@function f($frame) {
  @return percentage( $frame / $totalframes )
}
@robweychert
robweychert / typographic-scale-generator.md
Last active October 26, 2021 13:21
Sass typographic scale generator

Sass typographic scale generator

Generate a typographic scale of CSS variables with any interval (fixed or proportional) and any number of sizes. Just edit $interval, $body-text, $scale-min, and $scale-max:

:root {
  $interval: 1.5;    // Unitless for proportional, unit for fixed
  $body-text: 1rem;  // Must have a unit
  $scale-min: -2;    // Unitless negative integer
  $scale-max: 2;     // Unitless positive integer
@robweychert
robweychert / ap-style-month-strftime-liquid.md
Last active February 18, 2020 14:35
AP style month abbreviations with strftime in Liquid

AP style month abbreviations with strftime in Liquid

AP style is particular about how dates are formatted in various circumstances. strftime uses %b for month abbreviations, but its format (the first three letters of the month: Jan, Feb, etc) differs from AP style’s preferred abbreviations for some months. This Liquid snippet converts strftime’s month abbreviations to AP style:

{{ object | date: '%b. %e, %Y' | replace: 'Mar.', 'March' | replace: 'Apr.', 'April' | replace: 'May.', 'May' | replace: 'Jun.', 'June' | replace: 'Jul.', 'July' | replace: 'Sep.', 'Sept.' }}

For example, this Liquid code…

@robweychert
robweychert / python-easing-function.md
Last active March 24, 2024 13:48
Python easing functions
@robweychert
robweychert / eleventy.config.js
Last active March 3, 2024 16:44
Custom collections in Eleventy based on your posts’ front matter
module.exports = function(eleventyConfig) {
// Make a custom collection based on a key in your posts' front matter
function addCollectionByKey(collectionName, postKey, paginate=true, postsPerPage=100) {
eleventyConfig.addCollection(collectionName, function(collectionApi) {
const collectionObjects = {};
let collectionFinal = [];