Skip to content

Instantly share code, notes, and snippets.

View souporserious's full-sized avatar

Travis Arnold souporserious

View GitHub Profile
@souporserious
souporserious / GitHubSponsorTiers.tsx
Last active September 19, 2024 22:21
Display a list of GitHub sponsors by tier in React.
import { GitHubSponsors } from './GitHubSponsors'
export function GitHubSponsorTiers() {
return (
<GitHubSponsors
tiers={{
100: {
title: 'Bronze',
icon: '🥉',
},
const seenStyleElements = new Set<HTMLStyleElement>()
const cache = new Set<string>()
function processStyleRule(
rule: CSSStyleRule,
sheet: CSSStyleSheet,
index: number
) {
const selector = rule.selectorText
const className = selector.match(/\.([a-zA-Z0-9_-]+)/)![1]!
title date
Collections
2024-07-10

Collections

Collections are a way to group and organize related files. They can be used to generate static pages, create navigations, and more. At their core, they abstract directories and files into a Source, allowing you to analyze and render them programmatically.

Routing

@souporserious
souporserious / initializeOnce.ts
Created July 17, 2024 22:36
Execute a callback once for the lifetime of the process.
import {
existsSync,
mkdirSync,
readFileSync,
writeFileSync,
unlinkSync,
} from 'node:fs'
import { resolve } from 'node:path'
import { homedir } from 'node:os'
function reformatJsDocComment(comment, maxWidth = 80) {
// Extract the content of the JSDoc comment
const content = comment
.split('\n')
.filter(line => line.trim() !== '/**' && line.trim() !== '*/') // TODO: handle inline JS Doc
.map(line => line.replace(/^\s*\/?\**\s?/g, '').replace(/\s*\*\/?$/, '').trim())
.join(' ');
// Split the content into words
const words = content.split(/\s+/);
@souporserious
souporserious / lock-scroll.js
Last active May 8, 2024 09:33
lock scrollbars
/**
* Lock all scrollbars by disabling mousewheel and locking scrollbars in position
* Optionally provide an element to allow it to scroll when hovered
*/
const listenerOptions = supportsPassiveEvents
? { capture: true, passive: false }
: true
let lockedScrolls = []
function lockScroll(node) {
import { readFileSync } from 'node:fs'
import { resolve } from 'node:path'
function extractPort(script: string) {
const portRegex = /next dev.*(?:-p |--port )(\d+)/
const match = script.match(portRegex)
return match ? match[1] : null
}
/* Read package.json and parse the Next.js port number */
/** Get the offset ancestors of a node. */
function getOffsetAncestors(node: HTMLElement): Set<HTMLElement> {
let ancestors = new Set<HTMLElement>()
let current: Element | null = node.offsetParent
while (current) {
if (current instanceof HTMLElement) {
ancestors.add(current)
current = current.offsetParent
} else {
break
'use client'
import { useState, useLayoutEffect, useRef, useMemo } from 'react'
export function VirtualList({
data,
rowHeight,
itemsToShow = 4,
overscanCount = 2,
}: {
data: { text: string; id: number }[]
import * as webpack from 'webpack'
import { glob } from 'glob'
import { dirname, resolve } from 'node:path'
function getPathnameFromFilename(filename: string) {
return (
filename
// Remove file extensions
.replace(/\.[^/.]+$/, '')
// Remove leading "./"