diff --git a/src/collections/EventTypes.ts b/src/collections/EventTypes.ts index 286df34..22f6535 100644 --- a/src/collections/EventTypes.ts +++ b/src/collections/EventTypes.ts @@ -5,6 +5,29 @@ const EventTypes: CollectionConfig = { access: { read: () => true, }, + hooks: { + afterRead: [ + ({ doc }) => { + const hashCode = (str) => { + let hash = 0; + + for (let i = 0; i < str.length; i++) + hash = str.charCodeAt(i) + ((hash << 5) - hash); + + + return hash; + }; + + const pickColour = (str) => { + return `hsl(${hashCode(str) % 360}, 100%, 50%)`; + }; + + doc.backgroundColour = pickColour(doc.name); + + return doc; + } + ] + }, admin: { useAsTitle: 'name' },