-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathadmin.ts
More file actions
678 lines (642 loc) · 31.5 KB
/
Copy pathadmin.ts
File metadata and controls
678 lines (642 loc) · 31.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
// Config-driven admin: one resource registry drives list views, edit forms and
// generic persistence with cache invalidation. Add a column → add a field here.
import { all, first, run, uuid, nowSec, slugify } from "./db";
import { invalidate, invalidateMany, NS } from "./cache";
import { indexRow, unindexRow } from "./search";
export type FieldType =
| "text"
| "textarea"
| "markdown"
| "number"
| "boolean"
| "select"
| "datetime"
| "image"
| "tags"
| "color";
export interface Field {
name: string;
label: string;
type: FieldType;
options?: { value: string; label: string }[];
required?: boolean;
help?: string;
placeholder?: string;
full?: boolean; // span both columns
}
export interface Resource {
key: string;
label: string;
singular: string;
table: string;
icon: string;
ns: string[]; // cache namespaces to invalidate on write
searchable?: boolean; // index published/active rows into Vectorize for /api/search
fields: Field[];
listColumns: { name: string; label: string }[];
defaultSort: string;
}
const opt = (...vals: string[]) => vals.map((v) => ({ value: v, label: v }));
// Turkey is a fixed UTC+3 (no DST) — convert datetime-local <-> epoch cleanly.
const TR_OFFSET = "+03:00";
export const toLocalInput = (sec: number | null | undefined): string =>
sec == null ? "" : new Date((sec + 3 * 3600) * 1000).toISOString().slice(0, 16);
const fromLocalInput = (s: string): number | null => {
if (!s) return null;
const ms = Date.parse(`${s}:00${TR_OFFSET}`);
return Number.isNaN(ms) ? null : Math.floor(ms / 1000);
};
const COMMUNITY = opt("multigroup", "multiacademy");
const SECTORS = opt(
"Fintech", "Banka", "E-ticaret", "Oyun", "Yapay Zekâ", "Mobilite", "Telekom",
"Bulut & Altyapı", "Siber Güvenlik", "Danışmanlık", "Yazılım", "Medya & Eğlence",
"Eğitim", "Kamu", "Sağlık", "Otomotiv", "Havacılık & Savunma", "Perakende",
"İnsan Kaynakları", "Diğer",
);
const ACCENTS = opt("violet", "iris", "cyan", "lime", "amber", "coral", "magenta");
const ICONS = opt(
"link", "instagram", "twitter", "linkedin", "youtube", "github", "globe",
"calendar", "mail", "book-open", "play", "users", "sparkles", "external", "map-pin",
);
// Icons available for /kaynakca resource cards (all exist in Icon.astro).
const RES_ICONS = opt(
"book-open", "sparkles", "cpu", "code", "smartphone", "layers", "users",
"github", "globe", "play",
);
const RES_GROUPS = [
{ value: "kaynakca", label: "Kaynakça & Derlemeler" },
{ value: "bootcamp", label: "Bootcamp & Kurslar" },
{ value: "diger", label: "Topluluk & Diğer" },
];
export const RESOURCES: Record<string, Resource> = {
events: {
key: "events",
label: "Events",
singular: "Event",
table: "events",
icon: "calendar",
ns: [NS.events, NS.home],
searchable: true,
defaultSort: "COALESCE(starts_at, 9999999999) DESC",
listColumns: [
{ name: "title", label: "Title" },
{ name: "community", label: "Community" },
{ name: "starts_at", label: "Date" },
{ name: "status", label: "Status" },
],
fields: [
{ name: "title", label: "Title", type: "text", required: true },
{ name: "slug", label: "Slug", type: "text", help: "Leave blank to auto-generate from title." },
{ name: "summary", label: "Summary", type: "textarea", full: true, help: "One-line teaser shown on cards." },
{ name: "description", label: "Description", type: "markdown", full: true },
{ name: "cover_image", label: "Cover image", type: "image" },
{ name: "community", label: "Community", type: "select", options: COMMUNITY },
{ name: "category", label: "Category", type: "select", options: opt("meetup", "workshop", "bootcamp", "talk", "panel", "hackathon") },
{ name: "starts_at", label: "Starts", type: "datetime" },
{ name: "ends_at", label: "Ends", type: "datetime" },
{ name: "is_online", label: "Online event", type: "boolean" },
{ name: "location", label: "Venue", type: "text" },
{ name: "city", label: "City", type: "text" },
{ name: "registration_url", label: "Registration URL (Gathin/Kommunity)", type: "text", full: true },
{ name: "source", label: "Source", type: "select", options: opt("manual", "gathin", "kommunity") },
{ name: "status", label: "Status", type: "select", options: opt("published", "draft") },
{ name: "is_featured", label: "Feature in site banner", type: "boolean" },
{ name: "tags", label: "Tags", type: "tags" },
{ name: "sort_order", label: "Sort order", type: "number" },
],
},
posts: {
key: "posts",
label: "Blog",
singular: "Post",
table: "posts",
icon: "pen",
ns: [NS.posts, NS.home],
searchable: true,
defaultSort: "COALESCE(published_at, created_at) DESC",
listColumns: [
{ name: "title", label: "Title" },
{ name: "category", label: "Category" },
{ name: "status", label: "Status" },
{ name: "published_at", label: "Published" },
],
fields: [
{ name: "title", label: "Title", type: "text", required: true },
{ name: "slug", label: "Slug", type: "text", help: "Leave blank to auto-generate." },
{ name: "excerpt", label: "Excerpt", type: "textarea", full: true },
{ name: "body_md", label: "Body (Markdown)", type: "markdown", full: true },
{ name: "cover_image", label: "Cover image", type: "image" },
{ name: "category", label: "Category", type: "select", options: opt("guides", "news", "recap", "engineering", "community") },
{ name: "author", label: "Author", type: "text" },
{ name: "author_avatar", label: "Author avatar", type: "image" },
{ name: "author_title", label: "Author title / role", type: "text" },
{ name: "author_url", label: "Author link (LinkedIn etc.)", type: "text" },
{ name: "reading_minutes", label: "Reading minutes", type: "number" },
{ name: "tags", label: "Tags", type: "tags" },
{ name: "status", label: "Status", type: "select", options: opt("draft", "published") },
{ name: "featured", label: "Featured", type: "boolean" },
{ name: "published_at", label: "Published at", type: "datetime" },
{ name: "seo_title", label: "SEO title", type: "text", full: true },
{ name: "seo_description", label: "SEO description", type: "textarea", full: true },
],
},
links: {
key: "links",
label: "Links",
singular: "Link",
table: "links",
icon: "link",
ns: [NS.links, NS.home],
searchable: true,
defaultSort: "sort_order ASC",
listColumns: [
{ name: "label", label: "Label" },
{ name: "group_name", label: "Group" },
{ name: "clicks", label: "Clicks" },
{ name: "is_active", label: "Active" },
],
fields: [
{ name: "label", label: "Label", type: "text", required: true },
{ name: "url", label: "URL", type: "text", required: true, full: true },
{ name: "description", label: "Description", type: "text", full: true },
{ name: "icon", label: "Icon", type: "select", options: ICONS },
{ name: "group_name", label: "Group", type: "select", options: opt("primary", "communities", "academy", "resources", "social", "links") },
{ name: "accent", label: "Accent colour", type: "color", options: ACCENTS },
{ name: "sort_order", label: "Sort order", type: "number" },
{ name: "is_active", label: "Active", type: "boolean" },
],
},
"academy-links": {
key: "academy-links",
label: "Academy Links",
singular: "Academy link",
table: "academy_links",
icon: "sparkles",
ns: [NS.academyLinks],
defaultSort: "sort_order ASC",
listColumns: [
{ name: "label", label: "Label" },
{ name: "group_name", label: "Group" },
{ name: "clicks", label: "Clicks" },
{ name: "is_active", label: "Active" },
],
fields: [
{ name: "label", label: "Label", type: "text", required: true },
{ name: "url", label: "URL", type: "text", required: true, full: true },
{ name: "description", label: "Description", type: "text", full: true },
{ name: "icon", label: "Icon", type: "select", options: ICONS },
{ name: "group_name", label: "Group", type: "select", options: opt("primary", "academy", "resources", "social", "links") },
{ name: "accent", label: "Accent colour", type: "color", options: ACCENTS },
{ name: "sort_order", label: "Sort order", type: "number" },
{ name: "is_active", label: "Active", type: "boolean" },
],
},
hero: {
key: "hero",
label: "Hero slides",
singular: "Hero slide",
table: "hero_slides",
icon: "camera",
ns: [NS.hero, NS.home],
defaultSort: "sort_order ASC, created_at ASC",
listColumns: [
{ name: "title", label: "Title" },
{ name: "sort_order", label: "Order" },
{ name: "is_active", label: "Active" },
],
fields: [
{ name: "image_url", label: "Photo", type: "image", required: true, full: true, help: "Ana sayfadaki hero'nun arkasında akan foto bandı. Yükle ya da URL yapıştır. Liste tamamen boşalırsa varsayılan 5 fotoğrafa döner." },
{ name: "title", label: "Title", type: "text", help: "Sadece admin listesinde görünür." },
{ name: "sort_order", label: "Sort order", type: "number" },
{ name: "is_active", label: "Active", type: "boolean" },
],
},
resources: {
key: "resources",
label: "Kaynakça",
singular: "Resource",
table: "resources",
icon: "book-open",
ns: [NS.resources],
defaultSort: "sort_order ASC, created_at ASC",
listColumns: [
{ name: "title", label: "Title" },
{ name: "group_name", label: "Group" },
{ name: "lang", label: "Lang" },
{ name: "is_active", label: "Active" },
],
fields: [
{ name: "title", label: "Title", type: "text", required: true },
{ name: "url", label: "URL (GitHub repo)", type: "text", required: true, full: true },
{ name: "description", label: "Description", type: "textarea", full: true },
{ name: "icon", label: "Icon", type: "select", options: RES_ICONS },
{ name: "group_name", label: "Group", type: "select", options: RES_GROUPS },
{ name: "lang", label: "Language (optional)", type: "text", help: "e.g. Kotlin, JavaScript — leave blank to hide the chip." },
{ name: "sort_order", label: "Sort order", type: "number" },
{ name: "is_active", label: "Active", type: "boolean" },
{ name: "is_soon", label: "Mark as “yakında”", type: "boolean" },
],
},
recordings: {
key: "recordings",
label: "Recordings",
singular: "Recording",
table: "recordings",
icon: "play",
ns: [NS.recordings, NS.home],
searchable: true,
defaultSort: "sort_order ASC",
listColumns: [
{ name: "title", label: "Title" },
{ name: "category", label: "Category" },
{ name: "video_count", label: "Videos" },
{ name: "duration_minutes", label: "Mins" },
{ name: "is_active", label: "Active" },
],
fields: [
{ name: "title", label: "Title", type: "text", required: true },
{ name: "description", label: "Description", type: "textarea", full: true },
{ name: "youtube_url", label: "YouTube playlist URL", type: "text", full: true, help: "Full playlist URL (https://www.youtube.com/playlist?list=...)." },
{ name: "playlist_id", label: "Playlist ID", type: "text", help: "The list= value. Used if URL is empty." },
{ name: "cover_image", label: "Cover image", type: "image", help: "Playlist thumbnail. Paste a YouTube thumbnail URL or upload." },
{ name: "category", label: "Category", type: "select", options: opt("event", "bootcamp", "talk", "series") },
{ name: "video_count", label: "Video count", type: "number" },
{ name: "duration_minutes", label: "Total minutes", type: "number", help: "Sum of all video lengths in minutes. Shown as hours on the site." },
{ name: "sort_order", label: "Sort order", type: "number" },
{ name: "is_active", label: "Active", type: "boolean" },
],
},
podcasts: {
key: "podcasts",
label: "Podcasts",
singular: "Podcast",
table: "podcasts",
icon: "play",
ns: [NS.podcasts, NS.home],
searchable: true,
defaultSort: "sort_order ASC, title ASC",
listColumns: [
{ name: "title", label: "Title" },
{ name: "show_name", label: "Show" },
{ name: "host", label: "Host" },
{ name: "schedule", label: "Schedule" },
{ name: "is_active", label: "Active" },
],
fields: [
{ name: "title", label: "Title", type: "text", required: true, help: 'The series name, e.g. "DataCast".' },
{ name: "slug", label: "Slug", type: "text", help: "Page lives at /podcasts/<slug>. Blank auto-generates from the title." },
{ name: "show_name", label: "Umbrella brand", type: "text", help: 'Sits above the title, e.g. "Dataly Hollows". Leave blank to hide.' },
{ name: "kicker", label: "Kicker", type: "text", full: true, help: "One-line promise shown under the title." },
{ name: "lede", label: "Lede", type: "textarea", full: true, help: "One paragraph. Used on the /podcasts card AND as the page hero paragraph." },
{ name: "body_md", label: "Intro (Markdown)", type: "markdown", full: true },
{ name: "cover_image", label: "Cover art", type: "image", help: "Wide (16:9) show art. Upload or paste a URL / R2 key." },
{ name: "host", label: "Host", type: "text" },
{ name: "host_slug", label: "Host team slug", type: "text", help: "A team member's slug — links the host to /team/<slug>. Optional." },
{ name: "schedule", label: "Schedule", type: "text", help: 'Free text, e.g. "Her Çarşamba 08.00".' },
{ name: "episode_length", label: "Episode length", type: "text", help: 'e.g. "25–30 dk".' },
{ name: "first_episode_at", label: "First episode", type: "datetime", help: "The pilot. Drives the countdown line before it airs." },
{ name: "spotify_url", label: "Spotify URL", type: "text", full: true, help: "Blank = listed as upcoming instead of linked." },
{ name: "apple_url", label: "Apple Podcasts URL", type: "text", full: true },
{ name: "youtube_url", label: "YouTube URL", type: "text", full: true },
{ name: "subscribe_url", label: "Notify-me URL (Gathin)", type: "text", full: true, help: "Where the “bölümlerden haberdar ol” CTA goes. Blank falls back to the Gathin community page." },
{ name: "highlights_json", label: "“Neler bekliyor” (JSON)", type: "textarea", full: true, placeholder: '[{"icon":"compass","title":"Gerçek kariyer hikâyeleri","text":"…"}]', help: "icon = an Icon.astro name (compass, cpu, quote, layers, play, sparkles, search, users, sort-arrows…)." },
{ name: "audience_json", label: "“Kimler için” (JSON)", type: "textarea", full: true, placeholder: '[{"icon":"sparkles","title":"Kariyerinin başında olanlar","text":"…"}]' },
{ name: "is_soon", label: "Mark as “yakında”", type: "boolean", help: "On until the first episode is out." },
{ name: "sort_order", label: "Sort order", type: "number" },
{ name: "is_active", label: "Active", type: "boolean" },
],
},
gallery: {
key: "gallery",
label: "Gallery",
singular: "Photo",
table: "gallery_items",
icon: "camera",
ns: [NS.gallery, NS.home],
defaultSort: "sort_order ASC, COALESCE(taken_at, created_at) DESC",
listColumns: [
{ name: "title", label: "Title" },
{ name: "album", label: "Album" },
{ name: "is_active", label: "Active" },
],
fields: [
{ name: "image_url", label: "Image", type: "image", required: true, full: true, help: "Upload a file or paste an image URL." },
{ name: "title", label: "Title", type: "text" },
{ name: "caption", label: "Caption", type: "text", full: true },
{ name: "album", label: "Album", type: "text", help: "Group photos by album name." },
{ name: "taken_at", label: "Taken at", type: "datetime" },
{ name: "width", label: "Width", type: "number" },
{ name: "height", label: "Height", type: "number" },
{ name: "sort_order", label: "Sort order", type: "number" },
{ name: "is_active", label: "Active", type: "boolean" },
],
},
team: {
key: "team",
label: "Team",
singular: "Member",
table: "team_members",
icon: "users",
ns: [NS.team, NS.home],
searchable: true,
defaultSort: "sort_order ASC, name ASC",
listColumns: [
{ name: "name", label: "Name" },
{ name: "role", label: "Title" },
{ name: "team", label: "Team" },
{ name: "is_active", label: "Active" },
],
fields: [
{ name: "name", label: "Name", type: "text", required: true },
{ name: "slug", label: "Slug", type: "text", help: "Public page lives at /team/<slug>. Leave blank to auto-generate from the name." },
{ name: "role", label: "Title (membership level)", type: "text" },
{ name: "team", label: "Active area / team", type: "text" },
{ name: "focus", label: "Focus areas", type: "tags", help: "Comma separated, e.g. Astro, Cloudflare, DX" },
{ name: "bio", label: "Short bio (card)", type: "textarea", full: true, help: "One or two lines — this is what the /team grid shows." },
{ name: "long_bio", label: "Profile page (Markdown)", type: "markdown", full: true, help: "The body of /team/<slug>. Optional — the page degrades to the short bio." },
{ name: "avatar_url", label: "Avatar", type: "image" },
{ name: "joined_at", label: "Joined", type: "datetime" },
{ name: "community", label: "Community", type: "select", options: [...COMMUNITY, { value: "both", label: "both" }] },
{ name: "socials", label: "Socials (JSON)", type: "textarea", full: true, placeholder: '{"linkedin":"https://...","github":"https://...","twitter":"https://...","instagram":"https://...","website":"https://..."}' },
{ name: "sort_order", label: "Sort order", type: "number" },
{ name: "is_active", label: "Active", type: "boolean" },
],
},
communities: {
key: "communities",
label: "Communities",
singular: "Community",
table: "communities",
icon: "users",
ns: [NS.communities, NS.home],
searchable: true,
defaultSort: "sort_order ASC, name ASC",
listColumns: [
{ name: "name", label: "Name" },
{ name: "ecosystem", label: "Ecosystem" },
{ name: "city", label: "City" },
{ name: "is_active", label: "Active" },
],
fields: [
{ name: "name", label: "Name", type: "text", required: true },
{ name: "ecosystem", label: "Ecosystem", type: "select", options: opt("MultiGroup UNIT", "Google", "Huawei", "Amazon", "IEEE", "Independent") },
{ name: "city", label: "City", type: "text" },
{ name: "logo_url", label: "Logo", type: "image" },
{ name: "instagram", label: "Instagram URL", type: "text" },
{ name: "url", label: "Website / link", type: "text" },
{ name: "sort_order", label: "Sort order", type: "number" },
{ name: "is_active", label: "Active", type: "boolean" },
],
},
// ACTIVE collaborations (/partnerships). Not `companies` (employers our
// speakers came from) and not `communities` (partner chapters).
partners: {
key: "partners",
label: "Partners",
singular: "Partner",
table: "partners",
icon: "sparkles",
ns: [NS.partners, NS.home],
searchable: true,
defaultSort: "featured DESC, sort_order ASC, name ASC",
listColumns: [
{ name: "name", label: "Name" },
{ name: "kicker", label: "Programme" },
{ name: "category", label: "Category" },
{ name: "is_active", label: "Active" },
],
fields: [
{ name: "name", label: "Name", type: "text", required: true },
{ name: "slug", label: "Slug", type: "text", help: "Page lives at /partnerships/<slug>. Blank auto-generates from the name." },
{ name: "kicker", label: "Programme name", type: "text", help: 'The work itself, e.g. "Android Workshop Serisi".' },
{ name: "lede", label: "Lede", type: "textarea", full: true, help: "One paragraph. Used on the index card AND as the page hero paragraph." },
{ name: "body_md", label: "Story (Markdown)", type: "markdown", full: true },
{ name: "logo_url", label: "Logo", type: "image" },
{ name: "hero_image", label: "Hero image", type: "image" },
{ name: "website", label: "Website", type: "text" },
{ name: "category", label: "Category", type: "text", help: 'Free text, e.g. "Android", "Platform", "AI".' },
{ name: "year_from", label: "Collaboration started", type: "datetime" },
{ name: "metrics_json", label: "Metrics (JSON)", type: "textarea", full: true, placeholder: '[{"value":"1.5k","label":"katılımcı"},{"value":"30+","label":"partner etkinliği"}]', help: "Rendered as animated counters. Max 4 read well." },
{ name: "gallery_json", label: "Media grid (JSON)", type: "textarea", full: true, placeholder: '[{"img":"partners/wite-1.jpg","title":"Oturum 1","caption":"Architecture","href":"https://…"}]' },
{ name: "featured", label: "Featured", type: "boolean", help: "Lifts the partner into the index hero rail." },
{ name: "sort_order", label: "Sort order", type: "number" },
{ name: "is_active", label: "Active", type: "boolean" },
],
},
companies: {
key: "companies",
label: "Companies",
singular: "Company",
table: "companies",
icon: "sparkles",
ns: [NS.companies, NS.home],
searchable: true,
defaultSort: "featured DESC, sort_order ASC, name ASC",
listColumns: [
{ name: "name", label: "Name" },
{ name: "sector", label: "Sector" },
{ name: "featured", label: "Featured" },
{ name: "in_strip", label: "Strip" },
{ name: "is_active", label: "Active" },
],
fields: [
{ name: "name", label: "Name", type: "text", required: true },
{ name: "slug", label: "Slug", type: "text", help: "Leave blank to auto-generate from name." },
{ name: "sector", label: "Sector", type: "select", options: SECTORS },
{ name: "logo_url", label: "Logo", type: "image", help: "Upload a transparent-background logo or paste a URL." },
{ name: "website", label: "Website", type: "text", full: true },
{ name: "description", label: "Description", type: "textarea", full: true, help: "One-line note about the company (optional)." },
{ name: "featured", label: "Featured", type: "boolean" },
{ name: "in_strip", label: "Ana sayfa logo şeridi", type: "boolean", help: "İşaretli şirketler ana sayfadaki kayan logo bandında görünür." },
{ name: "sort_order", label: "Sort order", type: "number" },
{ name: "is_active", label: "Active", type: "boolean" },
],
},
speakers: {
key: "speakers",
label: "Speakers",
singular: "Speaker",
table: "speakers",
icon: "users",
ns: [NS.speakers, NS.home],
searchable: true,
defaultSort: "featured DESC, talk_count DESC, name ASC",
listColumns: [
{ name: "name", label: "Name" },
{ name: "company", label: "Company" },
{ name: "talk_count", label: "Talks" },
{ name: "is_active", label: "Active" },
],
fields: [
{ name: "name", label: "Name", type: "text", required: true },
{ name: "slug", label: "Slug", type: "text", help: "Leave blank to auto-generate from name." },
{ name: "title", label: "Title / role", type: "text", help: 'e.g. "Senior iOS Engineer"' },
{ name: "company", label: "Company (display name)", type: "text" },
{ name: "company_id", label: "Company link (id)", type: "text", help: "Optional companies.id to link the logo." },
{ name: "bio", label: "Bio", type: "textarea", full: true },
{ name: "avatar_url", label: "Photo", type: "image" },
{ name: "socials", label: "Socials (JSON)", type: "textarea", full: true, placeholder: '{"linkedin":"https://...","github":"https://...","twitter":"https://...","website":"https://..."}' },
{ name: "tags", label: "Expertise tags", type: "tags" },
{ name: "featured", label: "Featured", type: "boolean" },
{ name: "sort_order", label: "Sort order", type: "number" },
{ name: "is_active", label: "Active", type: "boolean" },
],
},
social: {
key: "social",
label: "Social posts",
singular: "Social post",
table: "social_posts",
icon: "instagram",
ns: [NS.social, NS.home],
defaultSort: "sort_order ASC, COALESCE(posted_at, created_at) DESC",
listColumns: [
{ name: "platform", label: "Platform" },
{ name: "account", label: "Account" },
{ name: "is_active", label: "Active" },
],
fields: [
{ name: "platform", label: "Platform", type: "select", options: opt("instagram", "twitter", "linkedin", "youtube") },
{ name: "account", label: "Account", type: "select", options: COMMUNITY },
{ name: "post_url", label: "Post URL", type: "text", required: true, full: true },
{ name: "thumbnail", label: "Thumbnail", type: "image", help: "Upload a screenshot or paste an image URL." },
{ name: "caption", label: "Caption", type: "textarea", full: true },
{ name: "posted_at", label: "Posted at", type: "datetime" },
{ name: "sort_order", label: "Sort order", type: "number" },
{ name: "is_active", label: "Active", type: "boolean" },
],
},
};
// Site-wide settings (key/value), edited on its own page.
export const SETTINGS_FIELDS: Field[] = [
{ name: "site_title", label: "Site title", type: "text" },
{ name: "site_tagline", label: "Tagline", type: "text" },
{ name: "site_description", label: "Meta description", type: "textarea", full: true },
{ name: "ga_measurement_id", label: "Google Analytics 4 ID", type: "text", help: "e.g. G-XXXXXXXXXX — analytics goes live the moment this is set." },
{ name: "posthog_key", label: "PostHog project key", type: "text", help: "Public key, e.g. phc_… — enables product analytics, web vitals & session replay." },
{ name: "posthog_host", label: "PostHog host", type: "text", help: "Ingestion host. Default https://eu.i.posthog.com (EU cloud)." },
{ name: "sentry_dsn", label: "Sentry DSN (browser)", type: "text", help: "Public DSN, e.g. https://…@…ingest.de.sentry.io/… — enables client error monitoring." },
{ name: "analytics_enabled", label: "Analytics master switch", type: "boolean", help: "Off = no GA / PostHog / Sentry anywhere, regardless of keys." },
{ name: "gsc_verification", label: "Google Search Console token", type: "text", help: "The content value of the google-site-verification meta tag." },
{ name: "banner_enabled", label: "Show event banner", type: "boolean" },
{ name: "stat_events", label: "Events stat", type: "text", help: "Shown on home/about, e.g. 100+" },
{ name: "stat_members", label: "Members stat", type: "text", help: "e.g. 15,000+" },
{ name: "stat_recordings", label: "Recordings stat", type: "text", help: "e.g. 17+" },
{ name: "stat_companies", label: "Companies stat", type: "text", help: "e.g. 25+" },
{ name: "stat_speakers", label: "Speakers stat", type: "text", help: "e.g. 200+" },
{ name: "stat_cities", label: "Cities stat", type: "text" },
{ name: "stat_partner_reach", label: "Partnership reach stat", type: "text", help: "Cumulative people reached through collaborations, e.g. 750+ — shown on /partnerships." },
];
/* ── coercion ─────────────────────────────────────────────────────────────── */
function coerce(field: Field, raw: FormDataEntryValue | null): string | number | null {
const s = typeof raw === "string" ? raw : "";
switch (field.type) {
case "boolean":
return s === "on" || s === "1" || s === "true" ? 1 : 0;
case "number":
return s === "" ? 0 : parseInt(s, 10) || 0;
case "datetime":
return fromLocalInput(s);
default:
return s;
}
}
/* ── persistence ──────────────────────────────────────────────────────────── */
export const getResource = (key: string): Resource | null => RESOURCES[key] ?? null;
export async function listRows(
env: Env,
res: Resource,
limit = 200,
): Promise<Record<string, unknown>[]> {
return all<Record<string, unknown>>(
env.DB,
`SELECT * FROM ${res.table} ORDER BY ${res.defaultSort} LIMIT ?`,
[limit],
);
}
export async function getRow(
env: Env,
res: Resource,
id: string,
): Promise<Record<string, unknown> | null> {
return first<Record<string, unknown>>(env.DB, `SELECT * FROM ${res.table} WHERE id=? LIMIT 1`, [id]);
}
/** Upload a File to R2 and return its object key. */
export async function uploadImage(env: Env, file: File): Promise<string> {
const ext = (file.name.split(".").pop() || "bin").toLowerCase().replace(/[^a-z0-9]/g, "");
const key = `uploads/${nowSec()}-${uuid().slice(0, 8)}.${ext}`;
await env.MEDIA.put(key, await file.arrayBuffer(), {
httpMetadata: { contentType: file.type || "application/octet-stream" },
});
return key;
}
/**
* Insert or update a row from submitted form data. Handles file uploads for
* image fields, slug auto-generation, then upserts and invalidates caches.
*/
export async function saveRow(
env: Env,
res: Resource,
form: FormData,
): Promise<string> {
const id = (form.get("id") as string) || uuid();
// resolve image uploads first (field `<name>_file`)
const values: Record<string, string | number | null> = {};
for (const f of res.fields) {
if (f.type === "image") {
const file = form.get(`${f.name}_file`);
if (file instanceof File && file.size > 0) {
values[f.name] = await uploadImage(env, file);
continue;
}
}
values[f.name] = coerce(f, form.get(f.name));
}
// auto-slug — `name` covers team members / partners, which have no `title`
if (res.fields.some((f) => f.name === "slug") && !values.slug) {
const base =
(values.title as string) || (values.name as string) || (values.label as string) || "item";
values.slug = slugify(base);
}
const cols = res.fields.map((f) => f.name);
const placeholders = ["id", ...cols, "updated_at"].map(() => "?").join(", ");
const updates = [...cols, "updated_at"].map((c) => `${c}=excluded.${c}`).join(", ");
const sql = `INSERT INTO ${res.table} (id, ${cols.join(", ")}, updated_at)
VALUES (${placeholders})
ON CONFLICT(id) DO UPDATE SET ${updates}`;
const params = [id, ...cols.map((c) => values[c] ?? null), nowSec()];
await run(env.DB, sql, params);
await invalidateMany(env, res.ns);
// Keep the search index in step: upsert published/active rows, drop drafts.
// indexRow never throws and no-ops without Vectorize (e.g. local dev).
if (res.searchable) {
await indexRow(env, res.key, id, values);
await invalidate(env, NS.search);
}
return id;
}
export async function deleteRow(env: Env, res: Resource, id: string): Promise<void> {
await run(env.DB, `DELETE FROM ${res.table} WHERE id=?`, [id]);
await invalidateMany(env, res.ns);
if (res.searchable) {
await unindexRow(env, res.key, id);
await invalidate(env, NS.search);
}
}
export async function saveSettings(env: Env, form: FormData): Promise<void> {
const now = nowSec();
for (const f of SETTINGS_FIELDS) {
const value = String(coerce(f, form.get(f.name)) ?? "");
await run(
env.DB,
`INSERT INTO settings (key, value, updated_at) VALUES (?, ?, ?)
ON CONFLICT(key) DO UPDATE SET value=excluded.value, updated_at=excluded.updated_at`,
[f.name, value, now],
);
}
await invalidateMany(env, [NS.settings, NS.home]);
}
export async function countRows(env: Env, table: string): Promise<number> {
const r = await first<{ n: number }>(env.DB, `SELECT COUNT(*) n FROM ${table}`);
return r?.n ?? 0;
}