Skip to content

Instantly share code, notes, and snippets.

View knowler's full-sized avatar

Nathan Knowler knowler

View GitHub Profile
@knowler
knowler / shadow.pug
Last active January 12, 2024 20:06
Pug mixin for an open Declarative Shadow DOM that polyfills itself.
mixin shadow
template(shadowrootmode="open")
block
script.
{
const element = document.currentScript.parentElement;
if (!element.shadowRoot) {
element.attachShadow({ mode: "open"})
const template = element.querySelector(":scope > template[shadowrootmode=open]");
if (template) element.shadowRoot.appendChild(template.content.cloneNode(true));
/*
* Modern CSS crash course:
*
* - Leverage flexibility for everything. The web is magic paper that adapts to whatever viewport it’s in.
* - This means using `display` values like `flex` and `grid`.
* - Avoid using `@media` for setting sizes: use fluid type and spacing (i.e. `clamp()`, `min()`, `max()` math functions).
* - Use logical properties for sizing and spacing. This helps with internationalization.
* - Think in axes: block (vertical: top is start, bottom is end), inline (horizontal: left is start, right is end).
* - Those are the left-to-right/top-to-bottom equivalances, but for other writing modes/directions you’ll be setting the correct direction (e.g. in RTL, inline-start is right and inline-end is left).
* - For flexbox and grid: “align” properties apply to the block axis and “justify” properties apply to the inline axis.
@knowler
knowler / restart-animations-element.js
Created November 30, 2023 23:49
A web component for restarting all the animations on the page.
export class RestartAnimationsElement extends HTMLElement {
#controller;
get #buttonElement() { return this.shadowRoot.querySelector(':host > button'); }
connectedCallback() {
if (!this.shadowRoot) {
this.attachShadow({mode: 'open'});
this.shadowRoot.innerHTML = `<button type="button" part="button"><slot>Restart Animations</slot></button>`;
this.#controller = new AbortController();
@knowler
knowler / custom-element-expander.js
Last active November 10, 2023 19:49
deno run custom-element-expander.js
import {parseHTML} from "https://esm.sh/linkedom";
// This is just so IDEs use HTML syntax highlighting.
const html = String.raw;
const { window, document, customElements, HTMLElement } = parseHTML(html`
<!doctype html>
<html lang="en-ca">
<head>
<meta charset="utf-8">
@knowler
knowler / fontsource-with-remix.md
Last active February 21, 2024 17:03
Fontsource with Remix (pre-1.7.3)

Fontsource with Remix

Fontsource is designed to work with projects that bundle their CSS. You import their stylesheet and the bundler will place the fonts in your build directory and the CSS file will have the correct URL for the @font-face src.

Remix doesn’t bundle CSS and so while you can import their CSS file and add it to your links, the URL to font will be incorrect. It is still possible to use Fontsource with Remix. We just need to create our own @font-face declaration with the correct URL to the font (ideally, one that benefits from Remix’s asset fingerprinting). There’s a bit of manual set up, but once that’s done, you can serve the font on your site and benefit from updates for the font.

  1. Install your font:
    npm install --save @fontsource/montserrat
@knowler
knowler / app.css
Last active December 8, 2021 17:07
Potential future with ES Modules and Web Components (single HTML-module version)
main fancy-article::part(header) {
color: red;
}
aside fancy-article::part(header) {
color: blue;
}
@knowler
knowler / app.css
Last active December 8, 2021 17:06
Potential future with ES Modules and Web Components (multi-file version)
main fancy-article::part(header) {
color: red;
}
aside fancy-article::part(header) {
color: blue;
}
#!/bin/bash
# Regolith aka Un-Bedrock
# "But what if we need to hand it off to another agency?" No more!
# This script converts a Bedrock site to a normal WordPress structure.
# Run it from the root of a Bedrock project.
# Created by Nathan Knowler and Daniel Roe
echo "Converting Bedrock to a normal WordPress file structure..."
theme() { cd $(wp theme path)/$(wp option get stylesheet | cut -d/ -f1) }
mp3these () {
mkdir -p mp3-320
for input in "$@"
do sox -S $input -C 320 "mp3-320/${input%.*}.mp3"
done
}