|
| 1 | +import type { CElement } from '../types/content-elements'; |
| 2 | +import type { Alignment, AnImage } from '../types/story'; |
| 3 | + |
| 4 | +export const ContentElement = { |
| 5 | + divider: () => { |
| 6 | + return { |
| 7 | + type: 'divider' as const, |
| 8 | + }; |
| 9 | + }, |
| 10 | + text: (content: string, alignment: Alignment = 'left') => { |
| 11 | + return { |
| 12 | + type: 'text' as const, |
| 13 | + content, |
| 14 | + alignment, |
| 15 | + }; |
| 16 | + }, |
| 17 | + quote: (items: CElement[], citation = '', subtype: 'blockquote' | 'pullquote' = 'pullquote') => { |
| 18 | + return { |
| 19 | + type: 'quote' as const, |
| 20 | + subtype, |
| 21 | + citation: { |
| 22 | + type: 'text' as const, |
| 23 | + content: citation, |
| 24 | + }, |
| 25 | + content_elements: items, |
| 26 | + }; |
| 27 | + }, |
| 28 | + interstitial_link: (url: string, content: string) => { |
| 29 | + return { |
| 30 | + type: 'interstitial_link' as const, |
| 31 | + url, |
| 32 | + content, |
| 33 | + }; |
| 34 | + }, |
| 35 | + header: (content: string, level: number) => { |
| 36 | + return { |
| 37 | + type: 'header' as const, |
| 38 | + content, |
| 39 | + level, |
| 40 | + }; |
| 41 | + }, |
| 42 | + raw_html: (content: string) => { |
| 43 | + return { |
| 44 | + type: 'raw_html' as const, |
| 45 | + content, |
| 46 | + }; |
| 47 | + }, |
| 48 | + gallery: (id: string) => { |
| 49 | + return { |
| 50 | + type: 'reference' as const, |
| 51 | + referent: { |
| 52 | + type: 'gallery' as const, |
| 53 | + id, |
| 54 | + }, |
| 55 | + }; |
| 56 | + }, |
| 57 | + list: (type: 'ordered' | 'unordered', items: CElement[]) => { |
| 58 | + return { |
| 59 | + type: 'list' as const, |
| 60 | + list_type: type, |
| 61 | + items, |
| 62 | + }; |
| 63 | + }, |
| 64 | + link_list: (title: string, links: { content: string; url: string }[]) => { |
| 65 | + return { |
| 66 | + type: 'link_list' as const, |
| 67 | + title, |
| 68 | + items: links.map(({ content, url }) => { |
| 69 | + return { |
| 70 | + type: 'interstitial_link' as const, |
| 71 | + content, |
| 72 | + url, |
| 73 | + }; |
| 74 | + }), |
| 75 | + }; |
| 76 | + }, |
| 77 | + image: (id: string, properties?: AnImage) => { |
| 78 | + return { |
| 79 | + referent: { |
| 80 | + id, |
| 81 | + type: 'image' as const, |
| 82 | + referent_properties: { |
| 83 | + _id: id, |
| 84 | + type: 'image' as const, |
| 85 | + ...properties, |
| 86 | + }, |
| 87 | + }, |
| 88 | + type: 'reference' as const, |
| 89 | + }; |
| 90 | + }, |
| 91 | + jwPlayer: (id: string) => { |
| 92 | + return { |
| 93 | + embed: { |
| 94 | + config: {}, |
| 95 | + id, |
| 96 | + url: 'https://cdn.jwplayer.com/players', |
| 97 | + }, |
| 98 | + subtype: 'jw_player' as const, |
| 99 | + type: 'custom_embed' as const, |
| 100 | + }; |
| 101 | + }, |
| 102 | + twitter: (id: string, provider = 'https://publish.twitter.com/oembed?url=') => { |
| 103 | + return { |
| 104 | + referent: { |
| 105 | + id, |
| 106 | + provider, |
| 107 | + service: 'oembed' as const, |
| 108 | + type: 'twitter' as const, |
| 109 | + }, |
| 110 | + type: 'reference' as const, |
| 111 | + }; |
| 112 | + }, |
| 113 | + youtube: (id: string, provider = 'https://www.youtube.com/oembed?url=') => { |
| 114 | + return { |
| 115 | + referent: { |
| 116 | + id, |
| 117 | + provider, |
| 118 | + service: 'oembed', |
| 119 | + type: 'youtube', |
| 120 | + }, |
| 121 | + type: 'reference' as const, |
| 122 | + }; |
| 123 | + }, |
| 124 | + facebook_video: (id: string, provider = 'https://www.facebook.com/plugins/post/oembed.json/?url=') => { |
| 125 | + return { |
| 126 | + referent: { |
| 127 | + id, |
| 128 | + provider, |
| 129 | + service: 'oembed', |
| 130 | + type: 'facebook-video', |
| 131 | + }, |
| 132 | + type: 'reference' as const, |
| 133 | + }; |
| 134 | + }, |
| 135 | + facebook_post: (id: string, provider = 'https://www.facebook.com/plugins/post/oembed.json/?url=') => { |
| 136 | + return { |
| 137 | + referent: { |
| 138 | + id, |
| 139 | + provider, |
| 140 | + service: 'oembed', |
| 141 | + type: 'facebook-post', |
| 142 | + }, |
| 143 | + type: 'reference' as const, |
| 144 | + }; |
| 145 | + }, |
| 146 | + soundcloud: (id: string, provider = 'https://soundcloud.com/oembed.json/?url=') => { |
| 147 | + return { |
| 148 | + referent: { |
| 149 | + id, |
| 150 | + provider, |
| 151 | + service: 'oembed', |
| 152 | + type: 'soundcloud', |
| 153 | + }, |
| 154 | + type: 'reference' as const, |
| 155 | + }; |
| 156 | + }, |
| 157 | + vimeo: (id: string, provider = 'https://vimeo.com/api/oembed.json?url=') => { |
| 158 | + return { |
| 159 | + referent: { |
| 160 | + id, |
| 161 | + provider, |
| 162 | + service: 'oembed', |
| 163 | + type: 'vimeo', |
| 164 | + }, |
| 165 | + type: 'reference' as const, |
| 166 | + }; |
| 167 | + }, |
| 168 | + instagram: (id: string, provider = 'https://api.instagram.com/oembed?url=') => { |
| 169 | + return { |
| 170 | + referent: { |
| 171 | + id, |
| 172 | + provider, |
| 173 | + service: 'oembed', |
| 174 | + type: 'instagram', |
| 175 | + }, |
| 176 | + type: 'reference' as const, |
| 177 | + }; |
| 178 | + }, |
| 179 | + dailymotion: (id: string, provider = 'https://www.dailymotion.com/services/oembed?url=') => { |
| 180 | + return { |
| 181 | + referent: { |
| 182 | + id, |
| 183 | + provider, |
| 184 | + service: 'oembed', |
| 185 | + type: 'dailymotion', |
| 186 | + }, |
| 187 | + type: 'reference' as const, |
| 188 | + }; |
| 189 | + }, |
| 190 | + tiktok: (id: string, provider = 'https://www.tiktok.com/oembed?url=') => { |
| 191 | + return { |
| 192 | + referent: { |
| 193 | + id, |
| 194 | + provider, |
| 195 | + service: 'oembed', |
| 196 | + type: 'tiktok', |
| 197 | + }, |
| 198 | + type: 'reference' as const, |
| 199 | + }; |
| 200 | + }, |
| 201 | +}; |
0 commit comments