Skip to content

Instantly share code, notes, and snippets.

View AlessioGr's full-sized avatar
🏔️

Alessio Gravili AlessioGr

🏔️
View GitHub Profile
@ozbeksu
ozbeksu / LinkBlock.ts
Last active February 27, 2023 00:42
PayloadCMS Revursive Block
import {Block} from 'payload/types';
const createRecursiveLinksBlock = (current = 0, maxDepth = 3): Block => {
if (current < maxDepth - 1) {
current++;
return {
slug: `Level ${current}`,
fields: [
{
name: 'name',
@AlessioGr
AlessioGr / PayloadCommunicator.ts
Last active March 12, 2023 12:34
Simple helper you can use to communicate with Payload CMS from your application via their REST API. Authorization via API key needs to be enabled in your users collection. More on enabling API keys here: https://payloadcms.com/docs/authentication/config#api-keys
import qs from 'qs';
export const cmsURL = "cms URL without the / at the end";
export const apiKey = "yourAPIkey";
export async function getDocuments (collectionName: string, whereQuery?) {
if (whereQuery) {
const stringifiedQuery = qs.stringify({
where: whereQuery
}, { addQueryPrefix: true });