@backgold/template-kit 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (340) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +12 -2
  3. package/dist/chunk-KOB36GSF.js +62 -0
  4. package/dist/constants-DvTNj4JI.d-Batjcj3Z.d.ts +38 -0
  5. package/dist/content-api-CYeY0vU8.d.ts +849 -0
  6. package/dist/contract/content-api-examples.d.ts +58 -0
  7. package/dist/contract/content-api-examples.js +783 -0
  8. package/dist/contract/content-api.d.ts +2 -0
  9. package/dist/contract/content-api.js +1 -0
  10. package/dist/contract/site-templates.d.ts +252 -0
  11. package/dist/contract/site-templates.js +185 -0
  12. package/package.json +70 -3
  13. package/src/components/EntryCard.astro +35 -0
  14. package/src/components/EventMap.astro +118 -0
  15. package/src/components/EventPage.astro +194 -0
  16. package/src/components/FieldValue.astro +41 -0
  17. package/src/components/LeadingHero.astro +21 -0
  18. package/src/components/NotFound.astro +20 -0
  19. package/src/components/PageSections.astro +47 -0
  20. package/src/components/Prose.astro +18 -0
  21. package/src/components/chrome/Brand.astro +54 -0
  22. package/src/components/chrome/ClosingCall.astro +94 -0
  23. package/src/components/chrome/DonateStrip.astro +61 -0
  24. package/src/components/chrome/FooterColumns.astro +32 -0
  25. package/src/components/chrome/FooterContact.astro +28 -0
  26. package/src/components/chrome/MenuList.astro +45 -0
  27. package/src/components/chrome/ModeToggle.astro +125 -0
  28. package/src/components/chrome/SignedInNotice.astro +53 -0
  29. package/src/components/chrome/SignupBand.astro +12 -0
  30. package/src/components/chrome/TakeoverBanner.astro +56 -0
  31. package/src/components/chrome/VisitorAccount.astro +82 -0
  32. package/src/components/entries/AuthorBox.astro +47 -0
  33. package/src/components/entries/EntryFields.astro +29 -0
  34. package/src/components/entries/EntryHeader.astro +77 -0
  35. package/src/components/entries/ListFrame.astro +126 -0
  36. package/src/components/entries/ListSearch.astro +24 -0
  37. package/src/components/entries/Share.astro +24 -0
  38. package/src/components/entries/course/classroom.astro +26 -0
  39. package/src/components/entries/course/lesson.astro +18 -0
  40. package/src/components/entries/course/section.ts +20 -0
  41. package/src/components/entries/course/syllabus.astro +15 -0
  42. package/src/components/entries/index.ts +77 -0
  43. package/src/components/entries/newsletter/issue.astro +41 -0
  44. package/src/components/entries/newsletter/list.astro +26 -0
  45. package/src/components/entries/podcast/episode.astro +42 -0
  46. package/src/components/entries/podcast/list.astro +36 -0
  47. package/src/components/entries/post/article.astro +31 -0
  48. package/src/components/entries/post/list.astro +85 -0
  49. package/src/components/entries/props.ts +61 -0
  50. package/src/components/entries/video/cards.astro +39 -0
  51. package/src/components/entries/video/grid.astro +15 -0
  52. package/src/components/entries/video/watch.astro +41 -0
  53. package/src/components/live/LivePage.astro +215 -0
  54. package/src/components/live/LocalTime.astro +29 -0
  55. package/src/components/sections/About/books.astro +188 -0
  56. package/src/components/sections/About/credentials.ts +90 -0
  57. package/src/components/sections/About/index.astro +57 -0
  58. package/src/components/sections/About/left.astro +54 -0
  59. package/src/components/sections/About/letter.astro +108 -0
  60. package/src/components/sections/About/portrait.astro +308 -0
  61. package/src/components/sections/Advocacy/compact.astro +14 -0
  62. package/src/components/sections/Advocacy/index.astro +14 -0
  63. package/src/components/sections/Band.astro +39 -0
  64. package/src/components/sections/Blog/feature.astro +176 -0
  65. package/src/components/sections/Blog/index.astro +37 -0
  66. package/src/components/sections/Blog/latest.ts +80 -0
  67. package/src/components/sections/Blog/list.astro +186 -0
  68. package/src/components/sections/Booking/index.astro +139 -0
  69. package/src/components/sections/Booking/list.astro +144 -0
  70. package/src/components/sections/Booking/types.ts +60 -0
  71. package/src/components/sections/Calendar/agenda.astro +14 -0
  72. package/src/components/sections/Calendar/index.astro +14 -0
  73. package/src/components/sections/CandidateRoster/ballot.astro +394 -0
  74. package/src/components/sections/CandidateRoster/candidates.ts +69 -0
  75. package/src/components/sections/CandidateRoster/compact.astro +115 -0
  76. package/src/components/sections/CandidateRoster/index.astro +57 -0
  77. package/src/components/sections/CaseStudies/beforeafter.astro +222 -0
  78. package/src/components/sections/CaseStudies/cases.ts +111 -0
  79. package/src/components/sections/CaseStudies/grid.astro +261 -0
  80. package/src/components/sections/CaseStudies/index.astro +333 -0
  81. package/src/components/sections/Classroom/CourseCard.astro +181 -0
  82. package/src/components/sections/Classroom/Courses.astro +88 -0
  83. package/src/components/sections/Classroom/classroom.ts +141 -0
  84. package/src/components/sections/Classroom/index.astro +20 -0
  85. package/src/components/sections/Classroom/list.astro +15 -0
  86. package/src/components/sections/Collection/compact.astro +7 -0
  87. package/src/components/sections/Collection/entries.ts +62 -0
  88. package/src/components/sections/Collection/feature.astro +180 -0
  89. package/src/components/sections/Collection/index.astro +46 -0
  90. package/src/components/sections/Collection/library.astro +271 -0
  91. package/src/components/sections/Collection/list.astro +7 -0
  92. package/src/components/sections/Collection/outline.astro +134 -0
  93. package/src/components/sections/Collection/shelves.astro +191 -0
  94. package/src/components/sections/Comparison/Unlisted.astro +6 -0
  95. package/src/components/sections/Comparison/cards.astro +171 -0
  96. package/src/components/sections/Comparison/index.astro +191 -0
  97. package/src/components/sections/Comparison/sides.ts +98 -0
  98. package/src/components/sections/Comparison/spectrum.astro +261 -0
  99. package/src/components/sections/ContentPost/banner.astro +152 -0
  100. package/src/components/sections/ContentPost/index.astro +35 -0
  101. package/src/components/sections/ContentPost/lesson.ts +119 -0
  102. package/src/components/sections/ContentPost/player.astro +254 -0
  103. package/src/components/sections/ContentPost/theater.astro +329 -0
  104. package/src/components/sections/Countdown/index.astro +53 -0
  105. package/src/components/sections/Course/Bar.astro +46 -0
  106. package/src/components/sections/Course/CourseHead.astro +123 -0
  107. package/src/components/sections/Course/Crumbs.astro +44 -0
  108. package/src/components/sections/Course/Icon.astro +29 -0
  109. package/src/components/sections/Course/Ring.astro +62 -0
  110. package/src/components/sections/Course/Syllabus.astro +146 -0
  111. package/src/components/sections/Course/course.ts +146 -0
  112. package/src/components/sections/Course/index.astro +143 -0
  113. package/src/components/sections/Course/outline.astro +39 -0
  114. package/src/components/sections/Cta/banner.astro +64 -0
  115. package/src/components/sections/Cta/card.astro +88 -0
  116. package/src/components/sections/Cta/index.astro +31 -0
  117. package/src/components/sections/Cta/photo.astro +114 -0
  118. package/src/components/sections/Cta/strip.astro +91 -0
  119. package/src/components/sections/Donate/index.astro +136 -0
  120. package/src/components/sections/Donate/story.astro +7 -0
  121. package/src/components/sections/Event/card.astro +14 -0
  122. package/src/components/sections/Event/index.astro +14 -0
  123. package/src/components/sections/EventsList/AgendaMonths.astro +105 -0
  124. package/src/components/sections/EventsList/CalendarLine.astro +23 -0
  125. package/src/components/sections/EventsList/EventRows.astro +196 -0
  126. package/src/components/sections/EventsList/LiveCounts.astro +75 -0
  127. package/src/components/sections/EventsList/TypeTabs.astro +53 -0
  128. package/src/components/sections/EventsList/agenda.astro +55 -0
  129. package/src/components/sections/EventsList/calendar.astro +392 -0
  130. package/src/components/sections/EventsList/cards.astro +186 -0
  131. package/src/components/sections/EventsList/cohorts.astro +205 -0
  132. package/src/components/sections/EventsList/compact.astro +163 -0
  133. package/src/components/sections/EventsList/events.ts +168 -0
  134. package/src/components/sections/EventsList/index.astro +46 -0
  135. package/src/components/sections/EventsList/map.astro +436 -0
  136. package/src/components/sections/EventsList/shifts.astro +355 -0
  137. package/src/components/sections/EventsList/week.astro +361 -0
  138. package/src/components/sections/Faq/Contact.astro +63 -0
  139. package/src/components/sections/Faq/Questions.astro +98 -0
  140. package/src/components/sections/Faq/cards.astro +74 -0
  141. package/src/components/sections/Faq/faq.ts +101 -0
  142. package/src/components/sections/Faq/index.astro +49 -0
  143. package/src/components/sections/Faq/topics.astro +178 -0
  144. package/src/components/sections/Financials/Foot.astro +38 -0
  145. package/src/components/sections/Financials/Head.astro +47 -0
  146. package/src/components/sections/Financials/donut.astro +197 -0
  147. package/src/components/sections/Financials/financials.ts +52 -0
  148. package/src/components/sections/Financials/index.astro +148 -0
  149. package/src/components/sections/Financials/table.astro +157 -0
  150. package/src/components/sections/FormBlock/index.astro +33 -0
  151. package/src/components/sections/FormBlock/wide.astro +7 -0
  152. package/src/components/sections/Hero/cover.astro +170 -0
  153. package/src/components/sections/Hero/donate.astro +209 -0
  154. package/src/components/sections/Hero/field.astro +390 -0
  155. package/src/components/sections/Hero/index.astro +52 -0
  156. package/src/components/sections/Hero/overlap.astro +151 -0
  157. package/src/components/sections/Hero/rotating.astro +30 -0
  158. package/src/components/sections/Hero/split.astro +96 -0
  159. package/src/components/sections/Hero/statement.astro +55 -0
  160. package/src/components/sections/Hero/video.astro +399 -0
  161. package/src/components/sections/Issues/checklist.astro +204 -0
  162. package/src/components/sections/Issues/drawer.astro +237 -0
  163. package/src/components/sections/Issues/index.astro +115 -0
  164. package/src/components/sections/Issues/issues.ts +37 -0
  165. package/src/components/sections/Issues/numbered.astro +79 -0
  166. package/src/components/sections/Issues/rows.astro +137 -0
  167. package/src/components/sections/Issues/steps.astro +81 -0
  168. package/src/components/sections/Issues/tabs.astro +322 -0
  169. package/src/components/sections/Leaderboard/index.astro +29 -0
  170. package/src/components/sections/Lesson/Door.astro +121 -0
  171. package/src/components/sections/Lesson/LessonBody.astro +416 -0
  172. package/src/components/sections/Lesson/Rail.astro +182 -0
  173. package/src/components/sections/Lesson/Tracker.astro +137 -0
  174. package/src/components/sections/Lesson/index.astro +27 -0
  175. package/src/components/sections/Lesson/lesson.ts +233 -0
  176. package/src/components/sections/Lesson/reading.astro +21 -0
  177. package/src/components/sections/Map/CoverageLine.astro +19 -0
  178. package/src/components/sections/Map/RegionMap.astro +109 -0
  179. package/src/components/sections/Map/bar.astro +160 -0
  180. package/src/components/sections/Map/index.astro +192 -0
  181. package/src/components/sections/Map/map.astro +275 -0
  182. package/src/components/sections/MediaKit/BioCard.astro +108 -0
  183. package/src/components/sections/MediaKit/Downloads.astro +88 -0
  184. package/src/components/sections/MediaKit/index.astro +183 -0
  185. package/src/components/sections/MediaKit/kit.ts +140 -0
  186. package/src/components/sections/MediaKit/press.astro +189 -0
  187. package/src/components/sections/MediaKit/speaker.astro +205 -0
  188. package/src/components/sections/Membership/Benefits.astro +42 -0
  189. package/src/components/sections/Membership/Check.astro +12 -0
  190. package/src/components/sections/Membership/Price.astro +61 -0
  191. package/src/components/sections/Membership/compare.astro +312 -0
  192. package/src/components/sections/Membership/index.astro +281 -0
  193. package/src/components/sections/Membership/offers.ts +169 -0
  194. package/src/components/sections/Membership/tiers.astro +217 -0
  195. package/src/components/sections/MovementMap/index.astro +50 -0
  196. package/src/components/sections/MovementTicker/index.astro +43 -0
  197. package/src/components/sections/Pathways/Doors.astro +147 -0
  198. package/src/components/sections/Pathways/Head.astro +37 -0
  199. package/src/components/sections/Pathways/index.astro +27 -0
  200. package/src/components/sections/Pathways/pathways.ts +100 -0
  201. package/src/components/sections/Pathways/quiz.astro +286 -0
  202. package/src/components/sections/Pathways/tabs.astro +271 -0
  203. package/src/components/sections/PdfEmbed/card.astro +99 -0
  204. package/src/components/sections/PdfEmbed/index.astro +26 -0
  205. package/src/components/sections/PdfEmbed/medium.astro +7 -0
  206. package/src/components/sections/PdfEmbed/tall.astro +7 -0
  207. package/src/components/sections/Petition/coverage.astro +14 -0
  208. package/src/components/sections/Petition/image.astro +14 -0
  209. package/src/components/sections/Petition/index.astro +14 -0
  210. package/src/components/sections/Petition/map.astro +14 -0
  211. package/src/components/sections/PlatformPlanks/anchors.ts +66 -0
  212. package/src/components/sections/PlatformPlanks/columns.astro +171 -0
  213. package/src/components/sections/PlatformPlanks/index.astro +56 -0
  214. package/src/components/sections/PlatformPlanks/longread.astro +250 -0
  215. package/src/components/sections/PollBlock/index.astro +30 -0
  216. package/src/components/sections/Portfolio/featured.astro +343 -0
  217. package/src/components/sections/Portfolio/index.astro +571 -0
  218. package/src/components/sections/Portfolio/strip.astro +173 -0
  219. package/src/components/sections/Portfolio/work.ts +100 -0
  220. package/src/components/sections/Progress/MatchClock.astro +166 -0
  221. package/src/components/sections/Progress/compact.astro +150 -0
  222. package/src/components/sections/Progress/index.astro +32 -0
  223. package/src/components/sections/Progress/match.astro +126 -0
  224. package/src/components/sections/Progress/ring.astro +179 -0
  225. package/src/components/sections/QuickDonate/DonateCard.astro +149 -0
  226. package/src/components/sections/QuickDonate/Picker.astro +95 -0
  227. package/src/components/sections/QuickDonate/band.astro +164 -0
  228. package/src/components/sections/QuickDonate/bar.astro +208 -0
  229. package/src/components/sections/QuickDonate/donate.ts +126 -0
  230. package/src/components/sections/QuickDonate/hero.astro +143 -0
  231. package/src/components/sections/QuickDonate/index.astro +73 -0
  232. package/src/components/sections/QuickDonate/jar.astro +225 -0
  233. package/src/components/sections/QuickDonate/ladder.astro +248 -0
  234. package/src/components/sections/QuoteStrip/carousel.astro +340 -0
  235. package/src/components/sections/QuoteStrip/index.astro +58 -0
  236. package/src/components/sections/QuoteStrip/logos.astro +226 -0
  237. package/src/components/sections/QuoteStrip/quotes.ts +61 -0
  238. package/src/components/sections/QuoteStrip/single.astro +92 -0
  239. package/src/components/sections/QuoteStrip/ticker.astro +319 -0
  240. package/src/components/sections/QuoteStrip/wall.astro +113 -0
  241. package/src/components/sections/Resources/band.astro +93 -0
  242. package/src/components/sections/Resources/featured.astro +239 -0
  243. package/src/components/sections/Resources/index.astro +225 -0
  244. package/src/components/sections/Resources/resources.ts +92 -0
  245. package/src/components/sections/SampleBallot/Position.astro +39 -0
  246. package/src/components/sections/SampleBallot/ballot.ts +92 -0
  247. package/src/components/sections/SampleBallot/cards.astro +299 -0
  248. package/src/components/sections/SampleBallot/index.astro +326 -0
  249. package/src/components/sections/SampleBallot/measures.astro +172 -0
  250. package/src/components/sections/Scorecard/grades.astro +141 -0
  251. package/src/components/sections/Scorecard/index.astro +294 -0
  252. package/src/components/sections/Scorecard/promise.astro +167 -0
  253. package/src/components/sections/Scorecard/votes.ts +83 -0
  254. package/src/components/sections/SectionHead.astro +31 -0
  255. package/src/components/sections/Services/Button.astro +24 -0
  256. package/src/components/sections/Services/Check.astro +12 -0
  257. package/src/components/sections/Services/Includes.astro +42 -0
  258. package/src/components/sections/Services/compare.astro +328 -0
  259. package/src/components/sections/Services/index.astro +187 -0
  260. package/src/components/sections/Services/list.astro +181 -0
  261. package/src/components/sections/Services/services.ts +80 -0
  262. package/src/components/sections/ShareKit/Actions.astro +71 -0
  263. package/src/components/sections/ShareKit/Buttons.astro +62 -0
  264. package/src/components/sections/ShareKit/compact.astro +123 -0
  265. package/src/components/sections/ShareKit/index.astro +160 -0
  266. package/src/components/sections/ShareKit/share.ts +60 -0
  267. package/src/components/sections/ShareKit/strip.astro +173 -0
  268. package/src/components/sections/SignupCapture/band.astro +7 -0
  269. package/src/components/sections/SignupCapture/index.astro +103 -0
  270. package/src/components/sections/SignupCapture/inline.astro +7 -0
  271. package/src/components/sections/SocialFeed/index.astro +34 -0
  272. package/src/components/sections/StatCards/feature.astro +143 -0
  273. package/src/components/sections/StatCards/index.astro +51 -0
  274. package/src/components/sections/StatCards/ribbon.astro +113 -0
  275. package/src/components/sections/StatCards/wall.astro +177 -0
  276. package/src/components/sections/Store/featured.astro +14 -0
  277. package/src/components/sections/Store/index.astro +14 -0
  278. package/src/components/sections/Stories/Status.astro +42 -0
  279. package/src/components/sections/Stories/StoryCards.astro +171 -0
  280. package/src/components/sections/Stories/cards.astro +42 -0
  281. package/src/components/sections/Stories/index.astro +238 -0
  282. package/src/components/sections/Stories/stories.ts +97 -0
  283. package/src/components/sections/Stories/timeline.astro +135 -0
  284. package/src/components/sections/TeamGrid/board.astro +280 -0
  285. package/src/components/sections/TeamGrid/index.astro +71 -0
  286. package/src/components/sections/TeamGrid/list.astro +306 -0
  287. package/src/components/sections/TeamGrid/people.ts +178 -0
  288. package/src/components/sections/VideoEmbed/index.astro +52 -0
  289. package/src/components/sections/VideoEmbed/landscape.astro +7 -0
  290. package/src/components/sections/VideoEmbed/portrait.astro +7 -0
  291. package/src/components/sections/VideoEmbed/square.astro +7 -0
  292. package/src/components/sections/VoterTools/DaysLeft.astro +33 -0
  293. package/src/components/sections/VoterTools/dates.astro +149 -0
  294. package/src/components/sections/VoterTools/index.astro +228 -0
  295. package/src/components/sections/VoterTools/polling.astro +141 -0
  296. package/src/components/sections/VoterTools/voter-tools.ts +70 -0
  297. package/src/components/sections/index.ts +370 -0
  298. package/src/components/sections/modules/Headed.astro +39 -0
  299. package/src/components/sections/modules/ModuleFrame.astro +179 -0
  300. package/src/components/volunteer/ShiftLive.astro +90 -0
  301. package/src/components/volunteer/detail.astro +247 -0
  302. package/src/components/volunteer/list.astro +298 -0
  303. package/src/components/volunteer/props.ts +21 -0
  304. package/src/env.d.ts +22 -0
  305. package/src/index.d.ts +10 -0
  306. package/src/index.js +64 -0
  307. package/src/layouts/Site.astro +371 -0
  308. package/src/lib/academy.ts +146 -0
  309. package/src/lib/brand.ts +534 -0
  310. package/src/lib/chrome.ts +119 -0
  311. package/src/lib/donate-frame.ts +64 -0
  312. package/src/lib/entries.ts +190 -0
  313. package/src/lib/env.ts +34 -0
  314. package/src/lib/event-map-draw.ts +91 -0
  315. package/src/lib/events.ts +476 -0
  316. package/src/lib/fonts.ts +116 -0
  317. package/src/lib/footer.ts +24 -0
  318. package/src/lib/format.ts +160 -0
  319. package/src/lib/geo.ts +131 -0
  320. package/src/lib/live.ts +54 -0
  321. package/src/lib/menu.ts +48 -0
  322. package/src/lib/petition-text.ts +29 -0
  323. package/src/lib/reading.ts +17 -0
  324. package/src/lib/regions.ts +215 -0
  325. package/src/lib/section.ts +94 -0
  326. package/src/lib/shifts.ts +186 -0
  327. package/src/lib/stream-time.ts +20 -0
  328. package/src/lib/stream.ts +141 -0
  329. package/src/lib/visitor.ts +54 -0
  330. package/src/routes/catch-all.astro +286 -0
  331. package/src/routes/form.astro +30 -0
  332. package/src/routes/live.astro +49 -0
  333. package/src/routes/not-found.astro +18 -0
  334. package/src/routes/preview.astro +60 -0
  335. package/src/routes/setup.astro +62 -0
  336. package/src/routes/volunteer-shift.astro +61 -0
  337. package/src/routes/volunteer.astro +37 -0
  338. package/src/styles/entries.css +784 -0
  339. package/src/styles/site.css +1839 -0
  340. package/src/template.ts +182 -0
@@ -0,0 +1,94 @@
1
+ // Reading a section from the Content API: its rows, media and links, each
2
+ // address already checked.
3
+
4
+ import type { Entry, Section } from '@backgold/content'
5
+ import { relFor, safeHref, safeSrc } from '@backgold/astro/server'
6
+ import { text } from './format'
7
+
8
+ export type Row = Record<string, unknown>
9
+
10
+ /** `data.items` rows that are objects. */
11
+ export function rows(section: Section): Row[] {
12
+ return (section.data?.items ?? []).filter((item): item is Row => !!item && typeof item === 'object' && !Array.isArray(item))
13
+ }
14
+
15
+ /** An array field of a row, as rows. */
16
+ export function nested(row: Row, key: string): Row[] {
17
+ const value = row[key]
18
+ return Array.isArray(value) ? value.filter((item): item is Row => !!item && typeof item === 'object' && !Array.isArray(item)) : []
19
+ }
20
+
21
+ export interface Media {
22
+ url: string
23
+ alt: string
24
+ }
25
+
26
+ /** The first of `keys` the section has media for, with a safe address. */
27
+ export function media(section: Section, ...keys: string[]): Media | null {
28
+ for (const key of keys) {
29
+ const m = section.media?.[key]
30
+ const url = m ? safeSrc(m.url) : null
31
+ if (url) return { url, alt: typeof m?.alt === 'string' ? m.alt : '' }
32
+ }
33
+ return null
34
+ }
35
+
36
+ /**
37
+ * A Hero's photo: the first of `keys` the section has media for, its alt text
38
+ * the section's `copy.imageAlt` (empty when the section has none).
39
+ */
40
+ export function heroPhoto(section: Section, ...keys: string[]): Media | null {
41
+ const m = media(section, ...keys)
42
+ return m ? { url: m.url, alt: text(section.copy.imageAlt) ?? '' } : null
43
+ }
44
+
45
+ export interface Link {
46
+ label: string
47
+ href: string
48
+ rel: 'noopener' | undefined
49
+ }
50
+
51
+ /** A link with a label and a safe address, or null. */
52
+ export function linkOf(label: unknown, href: unknown): Link | null {
53
+ const name = text(label)
54
+ const safe = safeHref(href, { anchors: true })
55
+ return name && safe ? { label: name, href: safe, rel: relFor(safe) } : null
56
+ }
57
+
58
+ /** The section's links, unsafe ones left out. */
59
+ export function links(section: Section): Link[] {
60
+ return (section.links ?? []).map((l) => linkOf(l.label, l.url)).filter((l): l is Link => l !== null)
61
+ }
62
+
63
+ /** A card for an entry: what EntryCard shows. */
64
+ export interface Card {
65
+ title: string
66
+ href: string | null
67
+ summary: string | null
68
+ image: Media | null
69
+ /** The entry's category, drawn as a chip: a `category` term first, else its first term. */
70
+ category: string | null
71
+ date: string | null
72
+ /** What the card says under its summary, before the day it was published. */
73
+ meta: string | null
74
+ }
75
+
76
+ export function entryCard(entry: Entry): Card {
77
+ const image = entry.hero ? safeSrc(entry.hero.url) : null
78
+ const category = entry.terms.find((t) => t.taxonomy === 'category') ?? entry.terms[0]
79
+ return {
80
+ title: entry.title,
81
+ href: entry.url ? safeHref(entry.url) : null,
82
+ summary: entry.summary,
83
+ image: image ? { url: image, alt: '' } : null,
84
+ category: category?.label ?? null,
85
+ date: entry.publish_at,
86
+ meta: null,
87
+ }
88
+ }
89
+
90
+ /** A page opens with a Hero that has a headline: that headline is its <h1>, and the Hero leads the page. */
91
+ export function leadsWithHero(sections: Section[]): boolean {
92
+ const first = sections[0]
93
+ return first?.type === 'Hero' && text(first.copy.headline) !== null
94
+ }
@@ -0,0 +1,186 @@
1
+ // The organization's volunteer shifts as the kit's volunteer pages draw them
2
+ // (src/routes/volunteer.astro, `/volunteer`, and
3
+ // src/routes/volunteer-shift.astro, `/volunteer/<slug>`), read from the
4
+ // Content API's `GET /shifts`: every open shift, soonest first, each with its
5
+ // counts, its state (`open`, `full`, `waitlist`, `closed`), what it belongs to
6
+ // and BackGold's sign-up card for it: `signup_embed.iframe`, the frame the
7
+ // shift's page sets in the site's look, and `signup_url`, the same card as a
8
+ // page of its own on BackGold, which a page links to when the api sends no
9
+ // frame (an api older than the frame). The counts move between publishes,
10
+ // so the pages draw them as built and read them again from `GET /shifts/live`
11
+ // after load (components/volunteer/ShiftLive.astro).
12
+ //
13
+ // Times are the organization's zone's (the row's `timezone`), as lib/format.ts
14
+ // writes them: "6:00 PM to 8:00 PM CDT" for a shift that ends the day it
15
+ // starts.
16
+
17
+ import type { Areas, BackgoldContent, SectionEmbed, ShiftsListRow } from '@backgold/content'
18
+ import { safeHref } from '@backgold/astro/server'
19
+ import { whenOf, monthName, type When } from '../components/sections/EventsList/events'
20
+
21
+ export const VOLUNTEER_PATH = '/volunteer'
22
+
23
+ /** A shift's own page on this site. */
24
+ export const shiftPath = (slug: string): string => `${VOLUNTEER_PATH}/${encodeURIComponent(slug)}`
25
+
26
+ /** A row of `GET /shifts` with the sign-up frame the api sends beside it; an older api sends none. */
27
+ export type ShiftRow = ShiftsListRow & { signup_embed?: { iframe: string | null } | null }
28
+
29
+ /** The most shifts the list reads (four pages of 50). */
30
+ const MOST = 200
31
+
32
+ /**
33
+ * Every open shift, soonest first, walking the feed's cursor up to MOST rows;
34
+ * null when the api does not serve the feed (an older api) or the read fails.
35
+ */
36
+ export async function openShifts(client: BackgoldContent): Promise<ShiftRow[] | null> {
37
+ const rows: ShiftRow[] = []
38
+ let cursor: string | undefined
39
+ try {
40
+ do {
41
+ const page = await client.shifts({ limit: 50, ...(cursor ? { cursor } : {}) })
42
+ rows.push(...(page.shifts as ShiftRow[]))
43
+ cursor = page.next_cursor ?? undefined
44
+ } while (cursor && rows.length < MOST)
45
+ } catch {
46
+ return rows.length > 0 ? rows : null
47
+ }
48
+ return rows.slice(0, MOST)
49
+ }
50
+
51
+ /** The areas of a volunteer page: those that show on every page and on pages that hold events (an EventsList holds an event). Null when the read fails. */
52
+ export async function volunteerAreas(client: BackgoldContent): Promise<Areas | null> {
53
+ try {
54
+ return (await client.areas({ holds: ['event'] })).areas
55
+ } catch {
56
+ return null
57
+ }
58
+ }
59
+
60
+ /** The shift's sign-up frame as ModuleFrame takes it, or null when the api sent none. */
61
+ export function signupEmbedOf(shift: ShiftRow): SectionEmbed | null {
62
+ const iframe = shift.signup_embed?.iframe
63
+ return typeof iframe === 'string' && iframe !== '' ? { iframe, script: '' } : null
64
+ }
65
+
66
+ /** A shift's button, by its state: words, and whether it draws as the quiet button (nothing to sign up for). */
67
+ export const SHIFT_ACTIONS: Record<ShiftsListRow['state'], { label: string; quiet: boolean }> = {
68
+ open: { label: 'Sign up', quiet: false },
69
+ waitlist: { label: 'Join the waitlist', quiet: false },
70
+ full: { label: 'Full', quiet: true },
71
+ closed: { label: 'Closed', quiet: true },
72
+ }
73
+
74
+ /** The most spots drawn as dots; past that, the words alone. */
75
+ export const MOST_DOTS = 24
76
+
77
+ /** One shift as the volunteer pages draw it. */
78
+ export interface ShiftView {
79
+ id: string
80
+ slug: string
81
+ title: string
82
+ startsAt: string
83
+ when: When | null
84
+ /** "6:00 PM to 8:00 PM CDT", the start's time alone across days, or null for an undated row. */
85
+ time: string | null
86
+ place: string | null
87
+ /** The shift's page on this site. */
88
+ href: string
89
+ state: ShiftsListRow['state']
90
+ action: { label: string; quiet: boolean }
91
+ signedUp: number
92
+ capacity: number | null
93
+ /** The counts in words, as the live script writes them too: "6 of 10 filled · 4 spots left". */
94
+ words: string
95
+ /** One per spot (`true` taken), up to MOST_DOTS; empty with no capacity or more spots than that. */
96
+ dots: boolean[]
97
+ }
98
+
99
+ /** A shift's counts in words: "6 of 10 filled · 4 spots left", "10 of 10 filled · Full", "3 signed up", or '' with no one yet and no capacity. */
100
+ export function countWords(signedUp: number, capacity: number | null): string {
101
+ if (capacity !== null && capacity > 0) {
102
+ const left = capacity - signedUp
103
+ return `${signedUp} of ${capacity} filled · ${left > 0 ? `${left} ${left === 1 ? 'spot' : 'spots'} left` : 'Full'}`
104
+ }
105
+ return signedUp > 0 ? `${signedUp} signed up` : ''
106
+ }
107
+
108
+ export function shiftView(shift: ShiftRow): ShiftView {
109
+ const when = whenOf(shift.starts_at, shift.timezone)
110
+ const end = whenOf(shift.ends_at, shift.timezone)
111
+ const sameDay = when && end && when.year === end.year && when.monthIndex === end.monthIndex && when.day === end.day
112
+ const capacity = typeof shift.capacity === 'number' && shift.capacity > 0 ? shift.capacity : null
113
+ const signedUp = Math.max(0, shift.signed_up)
114
+ return {
115
+ id: shift.id,
116
+ slug: shift.slug,
117
+ title: shift.title,
118
+ startsAt: shift.starts_at,
119
+ when,
120
+ time: when?.clock && sameDay && end?.time ? `${when.clock} to ${end.time}` : (when?.time ?? null),
121
+ place: shift.location?.trim() || null,
122
+ href: shiftPath(shift.slug),
123
+ state: shift.state,
124
+ action: SHIFT_ACTIONS[shift.state] ?? SHIFT_ACTIONS.closed,
125
+ signedUp,
126
+ capacity,
127
+ words: countWords(signedUp, capacity),
128
+ dots: capacity !== null && capacity <= MOST_DOTS ? Array.from({ length: capacity }, (_, i) => i < signedUp) : [],
129
+ }
130
+ }
131
+
132
+ /** The words of every state's button, for the live script. */
133
+ export const SHIFT_ACTION_LABELS = JSON.stringify(Object.fromEntries(Object.entries(SHIFT_ACTIONS).map(([state, a]) => [state, a.label])))
134
+
135
+ /** A run of shifts in one week, Monday to Sunday in the shifts' own calendar. */
136
+ export interface ShiftWeek {
137
+ /** The Monday, "2026-11-02", which the script matches to say This week and Next week; '' for undated rows. */
138
+ key: string
139
+ /** "Week of Nov 2"; null for undated rows. */
140
+ heading: string | null
141
+ /** "Nov 2 to 8", "Nov 30 to Dec 6"; null for undated rows. */
142
+ dates: string | null
143
+ shifts: ShiftView[]
144
+ }
145
+
146
+ const short = (d: Date) => `${monthName(d.getUTCMonth()).slice(0, 3)} ${d.getUTCDate()}`
147
+
148
+ /** The shifts grouped by week, in their order; a week with no shift is not drawn. */
149
+ export function weeksOf(shifts: ShiftView[]): ShiftWeek[] {
150
+ const weeks: ShiftWeek[] = []
151
+ for (const shift of shifts) {
152
+ let monday: Date | null = null
153
+ if (shift.when) {
154
+ monday = new Date(Date.UTC(shift.when.year, shift.when.monthIndex, Number(shift.when.day)))
155
+ monday.setUTCDate(monday.getUTCDate() - ((monday.getUTCDay() + 6) % 7))
156
+ }
157
+ const key = monday ? monday.toISOString().slice(0, 10) : ''
158
+ const last = weeks[weeks.length - 1]
159
+ if (last && last.key === key) {
160
+ last.shifts.push(shift)
161
+ continue
162
+ }
163
+ let dates: string | null = null
164
+ if (monday) {
165
+ const sunday = new Date(monday)
166
+ sunday.setUTCDate(sunday.getUTCDate() + 6)
167
+ dates = `${short(monday)} to ${sunday.getUTCMonth() === monday.getUTCMonth() ? sunday.getUTCDate() : short(sunday)}`
168
+ }
169
+ weeks.push({ key, heading: monday ? `Week of ${short(monday)}` : null, dates, shifts: [shift] })
170
+ }
171
+ return weeks
172
+ }
173
+
174
+ /** A maps search for the shift's place, or null with none. */
175
+ export function mapLinkOf(place: string | null): string | null {
176
+ return place ? safeHref(`https://www.google.com/maps/search/?api=1&query=${encodeURIComponent(place)}`) : null
177
+ }
178
+
179
+ const emitted = new WeakSet<Request>()
180
+
181
+ /** True the first time it is asked during one render, so a page carries one copy of the shifts' live script. */
182
+ export function firstShiftScript(request: Request): boolean {
183
+ if (emitted.has(request)) return false
184
+ emitted.add(request)
185
+ return true
186
+ }
@@ -0,0 +1,20 @@
1
+ // A live stream's moments in words, for the server and the browser alike (no
2
+ // imports, so components/live/LocalTime.astro's script can carry it): the
3
+ // server writes them in UTC, and the visitor's browser writes them again in
4
+ // its own zone with the same words.
5
+
6
+ /** `time`: "7:02 PM CDT" (when a stream went live). `day`: "Thursday, October 30 at 6:00 PM CDT" (when the next one starts). */
7
+ export type StreamMoment = 'time' | 'day'
8
+
9
+ const OPTIONS: Record<StreamMoment, Intl.DateTimeFormatOptions> = {
10
+ time: { hour: 'numeric', minute: '2-digit', timeZoneName: 'short' },
11
+ day: { weekday: 'long', month: 'long', day: 'numeric', hour: 'numeric', minute: '2-digit', timeZoneName: 'short' },
12
+ }
13
+
14
+ /** The moment in words, in `timeZone` (the reader's own when left out); null for a value that is not a date. */
15
+ export function streamTime(value: string | null | undefined, moment: StreamMoment, timeZone?: string): string | null {
16
+ if (!value) return null
17
+ const date = new Date(value)
18
+ if (Number.isNaN(date.getTime())) return null
19
+ return new Intl.DateTimeFormat('en-US', timeZone ? { ...OPTIONS[moment], timeZone } : OPTIONS[moment]).format(date)
20
+ }
@@ -0,0 +1,141 @@
1
+ // The organization's YouTube stream as the kit draws it: the header's Watch
2
+ // Live item (layouts/Site.astro) and the /live page (routes/live.astro).
3
+ //
4
+ // The stream is `GET /live`, read once a request by @backgold/astro's
5
+ // liveStreamOf (the client's `live()`: held 60 s in memory, never under the
6
+ // content version). The edge cache keys every page on it, so a page drawn
7
+ // while the channel is live is never served once it is off, and the other way
8
+ // round. A read that fails, or an api with no `GET /live` yet, is nothing
9
+ // live: no item, and /live says so.
10
+ //
11
+ // What a page draws from the stream is built here from its video id (a
12
+ // YouTube id, else the stream is drawn as nothing live): the player
13
+ // (`embed_url` with `autoplay=1&rel=0`), the live chat for this site's host
14
+ // (in YouTube's dark look, `dark_theme=1`, on a site that opens dark),
15
+ // the watch address, the still, and its moments in UTC, which the visitor's
16
+ // browser writes again in their own zone (components/live/LocalTime.astro).
17
+ // `embed_url`, `url` and `thumbnail_url` are used when they are YouTube's own
18
+ // addresses for that id; anything else is built from the id.
19
+
20
+ import type { Areas, Entry, LiveStream } from '@backgold/content'
21
+ import { liveStreamOf, safeSrc, type BackgoldReady, type MenuNode } from '@backgold/astro/server'
22
+ import { streamTime } from './stream-time'
23
+
24
+ /** The kit's page for the stream (routes/live.astro). */
25
+ export const LIVE_PATH = '/live'
26
+
27
+ /** A YouTube video id. */
28
+ const VIDEO_ID = /^[A-Za-z0-9_-]{6,20}$/
29
+ const PLAYER_HOSTS = new Set(['www.youtube.com', 'youtube.com', 'www.youtube-nocookie.com'])
30
+ const WATCH_HOSTS = new Set(['www.youtube.com', 'youtube.com', 'm.youtube.com', 'youtu.be'])
31
+
32
+ /** The request's stream (null while the channel is off the air, or when it could not be read). */
33
+ export function liveStream(bg: BackgoldReady): Promise<LiveStream | null> {
34
+ return liveStreamOf(bg)
35
+ }
36
+
37
+ /** A header menu node, marked when it is the Watch Live item (MenuList draws its dot). */
38
+ export type LiveMenuNode = MenuNode & { live?: boolean }
39
+
40
+ /**
41
+ * The header menu with Watch Live as its last item while the stream is live
42
+ * (not while it is only upcoming): current on /live. A menu that already
43
+ * links /live at its top level keeps its own link and gets no second one.
44
+ */
45
+ export function withWatchLive(nodes: MenuNode[], stream: LiveStream | null, pathname: string): LiveMenuNode[] {
46
+ if (stream?.status !== 'live' || nodes.some((node) => node.href === LIVE_PATH)) return nodes
47
+ const here = pathname.length > 1 ? pathname.replace(/\/+$/, '') : pathname
48
+ return [...nodes, { label: 'Watch Live', kind: 'page', href: LIVE_PATH, rel: undefined, current: here === LIVE_PATH, children: [], live: true }]
49
+ }
50
+
51
+ /** What a page draws of the stream. */
52
+ export interface StreamView {
53
+ status: 'live' | 'upcoming'
54
+ videoId: string
55
+ title: string
56
+ /** The watch address on YouTube. */
57
+ watchUrl: string
58
+ /** The player's address: the embed address with `autoplay=1&rel=0`. */
59
+ playerSrc: string
60
+ /** The live chat's address for this site's host, in YouTube's light look, or its dark one on a site that opens dark. */
61
+ chatSrc: string
62
+ /** The same chat in YouTube's dark look, for a template that draws it on a dark ground. */
63
+ chatSrcDark: string
64
+ /** The still: the stream's thumbnail, else YouTube's own for the id. */
65
+ still: string
66
+ /** When it went live, and the same in words in UTC (the server's text until the visitor's zone replaces it). */
67
+ startedAt: string | null
68
+ startedText: string | null
69
+ /** When an upcoming stream starts, and the same in words in UTC. */
70
+ scheduledAt: string | null
71
+ scheduledText: string | null
72
+ channelTitle: string | null
73
+ }
74
+
75
+ /** `raw` when it is an https address on one of `hosts` and passes `test`, else null. */
76
+ function youtubeUrl(raw: unknown, hosts: Set<string>, test: (url: URL) => boolean = () => true): URL | null {
77
+ if (typeof raw !== 'string') return null
78
+ try {
79
+ const url = new URL(raw)
80
+ return url.protocol === 'https:' && hosts.has(url.hostname) && test(url) ? url : null
81
+ } catch {
82
+ return null
83
+ }
84
+ }
85
+
86
+ /** The stream as a page draws it on `host` (`dark`: the site opens dark); null when it names no YouTube video id. */
87
+ export function streamView(stream: LiveStream, host: string, dark = false): StreamView | null {
88
+ const id = stream.video_id
89
+ if (!VIDEO_ID.test(id)) return null
90
+ const player = youtubeUrl(stream.embed_url, PLAYER_HOSTS, (url) => url.pathname === `/embed/${id}`) ?? new URL(`https://www.youtube.com/embed/${id}`)
91
+ player.search = ''
92
+ player.searchParams.set('autoplay', '1')
93
+ player.searchParams.set('rel', '0')
94
+ const watch = youtubeUrl(stream.url, WATCH_HOSTS)?.toString() ?? `https://www.youtube.com/watch?v=${id}`
95
+ const chat = new URL('https://www.youtube.com/live_chat')
96
+ chat.searchParams.set('v', id)
97
+ chat.searchParams.set('embed_domain', host)
98
+ const chatDark = new URL(chat)
99
+ chatDark.searchParams.set('dark_theme', '1')
100
+ return {
101
+ status: stream.status,
102
+ videoId: id,
103
+ title: stream.title.trim() || 'Live on YouTube',
104
+ watchUrl: watch,
105
+ playerSrc: player.toString(),
106
+ chatSrc: (dark ? chatDark : chat).toString(),
107
+ chatSrcDark: chatDark.toString(),
108
+ still: safeSrc(stream.thumbnail_url) ?? `https://i.ytimg.com/vi/${id}/hqdefault.jpg`,
109
+ startedAt: streamTime(stream.started_at, 'time') ? stream.started_at : null,
110
+ startedText: streamTime(stream.started_at, 'time', 'UTC'),
111
+ scheduledAt: streamTime(stream.scheduled_start_at, 'day') ? stream.scheduled_start_at : null,
112
+ scheduledText: streamTime(stream.scheduled_start_at, 'day', 'UTC'),
113
+ channelTitle: stream.channel_title?.trim() || null,
114
+ }
115
+ }
116
+
117
+ /** What the /live page's component is given: the kit's (components/live/LivePage.astro) or the template's `livePage`. */
118
+ export interface LivePageProps {
119
+ /** The stream while it is live or upcoming; null while the channel is off the air. */
120
+ stream: StreamView | null
121
+ /** The three newest videos (GET /entries/video), newest first; empty without a video type. */
122
+ videos: Entry[]
123
+ /** The videos' list, for "All videos"; null without one. */
124
+ videoList: { path: string; name: string } | null
125
+ /** Who goes live, for "When … goes live": the channel's name, else the organization's. */
126
+ channel: string
127
+ /** The page's areas (the video list's), which the layout draws around it. */
128
+ areas: Areas | null
129
+ }
130
+
131
+ /** The /live page's title and description in each state. */
132
+ export function liveHead(stream: StreamView | null, channel: string, siteName: string): { title: string; description: string } {
133
+ if (stream?.status === 'live') {
134
+ return { title: `Live now: ${stream.title} · ${siteName}`, description: `${channel} is live now: ${stream.title}. Watch the stream here.` }
135
+ }
136
+ if (stream) {
137
+ const when = stream.scheduledText ? ` on ${stream.scheduledText}` : ''
138
+ return { title: `Next live: ${stream.title} · ${siteName}`, description: `${channel} goes live${when}: ${stream.title}. Watch the stream here.` }
139
+ }
140
+ return { title: `Watch Live · ${siteName}`, description: `When ${channel} goes live, the stream plays here.` }
141
+ }
@@ -0,0 +1,54 @@
1
+ // Who is reading, and the academy's reads as that reader makes them: the
2
+ // Classroom, Course and Lesson sections and the course entry layouts read
3
+ // their courses through `academyReads` only, so a visitor's progress and
4
+ // locks come from the visitor-scoped reads and never from a section's baked
5
+ // (public, cached) data.
6
+ //
7
+ // `visitorOf` is `locals.backgold.visitor`: who @backgold/astro's middleware
8
+ // found signed in for this request (`GET /visitor` with the `bg_visitor`
9
+ // cookie's token), null for everyone else. `academyReads` passes
10
+ // `locals.backgold.visitorReads` (the visitor's token and its renewal, set by
11
+ // the same middleware; undefined signed out) to the client's `courses`,
12
+ // `course` and `lesson`: a signed-in visitor's read is theirs and never
13
+ // stored, anyone else's is the public, cached read. The kit never reads the
14
+ // token itself. `orgNameOf` is the organization's name from the site's
15
+ // `/site` answer (`locals.backgold.orgName`), for the doors and "Members of
16
+ // <org>".
17
+
18
+ import type { CourseResponse, CoursesResponse, LessonResponse, Visitor } from '@backgold/content'
19
+
20
+ /** The visitor signed in on this site for this request, or null. */
21
+ export function visitorOf(locals: App.Locals): Visitor | null {
22
+ return locals.backgold.visitor
23
+ }
24
+
25
+ /** The organization's name, or null while the site is not configured. */
26
+ export function orgNameOf(locals: App.Locals): string | null {
27
+ return locals.backgold.orgName || null
28
+ }
29
+
30
+ export interface AcademyReads {
31
+ visitor: Visitor | null
32
+ orgName: string | null
33
+ courses: () => Promise<CoursesResponse | null>
34
+ course: (slug: string) => Promise<CourseResponse | null>
35
+ lesson: (courseSlug: string, lessonSlug: string) => Promise<LessonResponse | null>
36
+ }
37
+
38
+ /** A slug the api could have minted: anything else is never sent. */
39
+ export const SLUG = /^[A-Za-z0-9][A-Za-z0-9_-]{0,120}$/
40
+
41
+ /** The academy's reads for this request: the visitor's while one is signed in, else the public reader's. */
42
+ export function academyReads(astro: { locals: App.Locals }): AcademyReads {
43
+ const bg = astro.locals.backgold
44
+ const none = async () => null
45
+ if (bg.setup !== null) return { visitor: null, orgName: null, courses: none, course: none, lesson: none }
46
+ const { client, visitorReads } = bg
47
+ return {
48
+ visitor: bg.visitor,
49
+ orgName: bg.orgName || null,
50
+ courses: () => client.courses(visitorReads),
51
+ course: (slug) => (SLUG.test(slug) ? client.course(slug, visitorReads) : none()),
52
+ lesson: (courseSlug, lessonSlug) => (SLUG.test(courseSlug) && SLUG.test(lessonSlug) ? client.lesson(courseSlug, lessonSlug, visitorReads) : none()),
53
+ }
54
+ }