|
| 1 | +import { defineType } from "sanity"; |
| 2 | +import type { IconType } from "react-icons"; |
| 3 | +import { |
| 4 | + FaBluesky, |
| 5 | + FaGithub, |
| 6 | + FaInstagram, |
| 7 | + FaLinkedin, |
| 8 | + FaMastodon, |
| 9 | + FaReddit, |
| 10 | + FaShareNodes, |
| 11 | + FaThreads, |
| 12 | + FaTiktok, |
| 13 | +} from "react-icons/fa6"; |
| 14 | + |
| 15 | +const socialFields = [ |
| 16 | + { |
| 17 | + name: "platform", |
| 18 | + type: "string", |
| 19 | + title: "Platform", |
| 20 | + description: "Optional: auto-detected from URL when left blank.", |
| 21 | + options: { |
| 22 | + list: [ |
| 23 | + { title: "Auto-detect from URL", value: "auto" }, |
| 24 | + { title: "X (Twitter)", value: "x" }, |
| 25 | + { title: "Bluesky", value: "bluesky" }, |
| 26 | + { title: "LinkedIn", value: "linkedin" }, |
| 27 | + { title: "Reddit", value: "reddit" }, |
| 28 | + { title: "TikTok", value: "tiktok" }, |
| 29 | + { title: "Instagram", value: "instagram" }, |
| 30 | + { title: "Threads", value: "threads" }, |
| 31 | + { title: "Mastodon", value: "mastodon" }, |
| 32 | + { title: "GitHub Gist", value: "gist" }, |
| 33 | + { title: "YouTube", value: "youtube" }, |
| 34 | + ], |
| 35 | + }, |
| 36 | + }, |
| 37 | + { |
| 38 | + name: "url", |
| 39 | + type: "url", |
| 40 | + title: "Post URL", |
| 41 | + validation: (rule: { required: () => unknown }) => rule.required(), |
| 42 | + }, |
| 43 | + { |
| 44 | + name: "author", |
| 45 | + type: "string", |
| 46 | + title: "Author Name (Optional)", |
| 47 | + }, |
| 48 | + { |
| 49 | + name: "handle", |
| 50 | + type: "string", |
| 51 | + title: "Author Handle (Optional)", |
| 52 | + }, |
| 53 | + { |
| 54 | + name: "fallbackText", |
| 55 | + type: "text", |
| 56 | + title: "Post Text / Fallback Excerpt (Optional)", |
| 57 | + rows: 3, |
| 58 | + }, |
| 59 | + { |
| 60 | + name: "caption", |
| 61 | + type: "string", |
| 62 | + title: "Caption (Optional)", |
| 63 | + }, |
| 64 | +]; |
| 65 | + |
| 66 | +function createPlatformEmbedSchema( |
| 67 | + name: string, |
| 68 | + title: string, |
| 69 | + defaultPlatform: string, |
| 70 | + icon: IconType, |
| 71 | +) { |
| 72 | + return defineType({ |
| 73 | + name, |
| 74 | + type: "object", |
| 75 | + title, |
| 76 | + icon, |
| 77 | + fields: socialFields, |
| 78 | + initialValue: { |
| 79 | + platform: defaultPlatform, |
| 80 | + }, |
| 81 | + preview: { |
| 82 | + select: { |
| 83 | + title: "author", |
| 84 | + subtitle: "url", |
| 85 | + }, |
| 86 | + prepare({ title: authorName, subtitle }) { |
| 87 | + return { |
| 88 | + title: authorName ? `${title}: ${authorName}` : title, |
| 89 | + subtitle: subtitle || "", |
| 90 | + }; |
| 91 | + }, |
| 92 | + }, |
| 93 | + }); |
| 94 | +} |
| 95 | + |
| 96 | +export const socialEmbed = createPlatformEmbedSchema( |
| 97 | + "socialEmbed", |
| 98 | + "Social Media Embed", |
| 99 | + "auto", |
| 100 | + FaShareNodes, |
| 101 | +); |
| 102 | +export const blueskyEmbed = createPlatformEmbedSchema( |
| 103 | + "bluesky", |
| 104 | + "Bluesky Embed", |
| 105 | + "bluesky", |
| 106 | + FaBluesky, |
| 107 | +); |
| 108 | +export const linkedinEmbed = createPlatformEmbedSchema( |
| 109 | + "linkedin", |
| 110 | + "LinkedIn Embed", |
| 111 | + "linkedin", |
| 112 | + FaLinkedin, |
| 113 | +); |
| 114 | +export const redditEmbed = createPlatformEmbedSchema( |
| 115 | + "reddit", |
| 116 | + "Reddit Embed", |
| 117 | + "reddit", |
| 118 | + FaReddit, |
| 119 | +); |
| 120 | +export const tiktokEmbed = createPlatformEmbedSchema( |
| 121 | + "tiktok", |
| 122 | + "TikTok Embed", |
| 123 | + "tiktok", |
| 124 | + FaTiktok, |
| 125 | +); |
| 126 | +export const instagramEmbed = createPlatformEmbedSchema( |
| 127 | + "instagram", |
| 128 | + "Instagram Embed", |
| 129 | + "instagram", |
| 130 | + FaInstagram, |
| 131 | +); |
| 132 | +export const threadsEmbed = createPlatformEmbedSchema( |
| 133 | + "threads", |
| 134 | + "Threads Embed", |
| 135 | + "threads", |
| 136 | + FaThreads, |
| 137 | +); |
| 138 | +export const mastodonEmbed = createPlatformEmbedSchema( |
| 139 | + "mastodon", |
| 140 | + "Mastodon Embed", |
| 141 | + "mastodon", |
| 142 | + FaMastodon, |
| 143 | +); |
| 144 | +export const githubGistEmbed = createPlatformEmbedSchema( |
| 145 | + "githubGist", |
| 146 | + "GitHub Gist Embed", |
| 147 | + "gist", |
| 148 | + FaGithub, |
| 149 | +); |
| 150 | + |
| 151 | +export default socialEmbed; |
0 commit comments