Skip to content

Instantly share code, notes, and snippets.

@paulpopus
paulpopus / RichText.tsx
Created March 12, 2024 02:05
Payload lexical rich text serialiser
import React from 'react'
import { serializeLexical } from './serialize'
const RichText: React.FC<{ className?: string; content: any }> = ({ className, content }) => {
if (!content) {
return null
}
return (
@paulpopus
paulpopus / middleware.ts
Created August 11, 2023 07:26
Nextjs Middleware for Payload authentication to redirect users based on authentication
import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'
import { CheckUserDocument } from '@/graphql/generated/client'
import { CheckUserQuery } from '@/graphql/generated/client'
/* Redirect away from these routes if not authenticated */
const protectedRoutes = ['/profile', '/search']
/* Redirect away from these routes if authenticated */
const publicRoutes = ['/login', '/register']
@paulpopus
paulpopus / RichTextSerialiser.tsx
Created July 8, 2023 16:07
Payload Slate.js Rich Text Serialiser
import React, { Fragment } from 'react'
import { Text as SlateText } from 'slate'
import Link from 'next/link'
import { getSectionForCollection } from '@utilities/getSectionForCollection'
function Serialise({ content }: any) {
return (
<>
{content?.map((node: any, i: number) => {
if (!node) {
@paulpopus
paulpopus / main.py
Last active December 12, 2020 17:13
Searching for a keyword in a list of songs
""" /requirements.txt
beautifulsoup4==4.9.3
lxml==4.6.2
soupsieve==2.1
"""
from bs4 import BeautifulSoup
from urllib.request import Request, urlopen
import lxml
import re