Skip to content

Instantly share code, notes, and snippets.

View Livog's full-sized avatar
🏠
Working from home

Fredrik Livog

🏠
Working from home
View GitHub Profile
@Livog
Livog / actions.ts
Last active March 7, 2025 16:45
Custom Payload Admin Bar RSC styled with Tailwind v4
'use server'
import {
PAYLOAD_TOKEN_COOKIE_NAME,
AUTH_JS_COOKIE_NAME,
AUTH_JS_SECURE_COOKIE_NAME,
BETTER_AUTH_SESSION_COOKIE_NAME,
BETTER_AUTH_SESSION_COOKIE_NAME_SECURE,
BETTER_AUTH_SESSION_DATA_COOKIE_NAME,
BETTER_AUTH_SESSION_DATA_COOKIE_NAME_SECURE
@Livog
Livog / config.ts
Last active February 14, 2025 07:02
Payload CMS 3.0 Path Field to simplify frontend querying
import type { CollectionSlug } from 'payload'
export const PATH_UNIQUE_AGINST_COLLECTIONS = ['pages', 'posts'] as const satisfies CollectionSlug[]
export const FIELD_TO_USE_FOR_PATH = 'slug' as const
@Livog
Livog / cache.ts
Last active February 3, 2025 19:01
A minimal caching utility for Next.js that stores large responses in .next/cache/custom using hashed filenames, auto-serves valid cached responses, and respects revalidation times. It supports forced refresh, helping you work around standard fetch cache size limits while seamlessly integrating with Next.js caching conventions.
import { createHash } from 'crypto'
import fs from 'fs/promises'
import { createWriteStream } from 'fs'
import path from 'path'
import { Readable } from 'stream'
import { finished } from 'stream/promises'
import { glob } from 'glob'
const CACHE_DIR = path.join(process.cwd(), '.next/cache/custom')
@Livog
Livog / Slider.tsx
Created February 29, 2024 17:10
Slider
'use client'
import 'swiper/css'
import 'swiper/css/navigation'
import { useRef, useState, useEffect, type ReactNode, type CSSProperties } from 'react'
import { Navigation } from 'swiper/modules'
import type { Swiper as SwiperType, SwiperOptions } from 'swiper/types'
import ChevronLeftIcon from '@public/icons/chevron-left.svg'
import ChevronRightIcon from '@public/icons/chevron-right.svg'
import clsx from 'clsx'