@backgold/template-kit 0.0.0-stage → 0.1.1

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 (349) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +12 -2
  3. package/dist/chunk-RJAVFRC6.js +67 -0
  4. package/dist/constants-BAIo_Q5U.d-lQbj1e1-.d.ts +48 -0
  5. package/dist/content-api-Cox1-wz5.d.ts +1096 -0
  6. package/dist/contract/content-api-examples.d.ts +72 -0
  7. package/dist/contract/content-api-examples.js +926 -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 +253 -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 +61 -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 +80 -0
  57. package/src/components/sections/About/index.astro +60 -0
  58. package/src/components/sections/About/left.astro +57 -0
  59. package/src/components/sections/About/letter.astro +111 -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 +126 -0
  102. package/src/components/sections/ContentPost/player.astro +254 -0
  103. package/src/components/sections/ContentPost/prose.astro +80 -0
  104. package/src/components/sections/ContentPost/theater.astro +329 -0
  105. package/src/components/sections/Countdown/index.astro +53 -0
  106. package/src/components/sections/Course/Bar.astro +46 -0
  107. package/src/components/sections/Course/CourseHead.astro +123 -0
  108. package/src/components/sections/Course/Crumbs.astro +44 -0
  109. package/src/components/sections/Course/Icon.astro +29 -0
  110. package/src/components/sections/Course/Ring.astro +62 -0
  111. package/src/components/sections/Course/Syllabus.astro +146 -0
  112. package/src/components/sections/Course/course.ts +146 -0
  113. package/src/components/sections/Course/index.astro +143 -0
  114. package/src/components/sections/Course/outline.astro +39 -0
  115. package/src/components/sections/Cta/banner.astro +64 -0
  116. package/src/components/sections/Cta/card.astro +88 -0
  117. package/src/components/sections/Cta/index.astro +31 -0
  118. package/src/components/sections/Cta/photo.astro +114 -0
  119. package/src/components/sections/Cta/strip.astro +91 -0
  120. package/src/components/sections/Donate/index.astro +136 -0
  121. package/src/components/sections/Donate/story.astro +7 -0
  122. package/src/components/sections/Event/card.astro +14 -0
  123. package/src/components/sections/Event/index.astro +14 -0
  124. package/src/components/sections/EventsList/AgendaMonths.astro +105 -0
  125. package/src/components/sections/EventsList/CalendarLine.astro +23 -0
  126. package/src/components/sections/EventsList/EventRows.astro +196 -0
  127. package/src/components/sections/EventsList/LiveCounts.astro +75 -0
  128. package/src/components/sections/EventsList/TypeTabs.astro +53 -0
  129. package/src/components/sections/EventsList/agenda.astro +55 -0
  130. package/src/components/sections/EventsList/calendar.astro +392 -0
  131. package/src/components/sections/EventsList/cards.astro +186 -0
  132. package/src/components/sections/EventsList/cohorts.astro +205 -0
  133. package/src/components/sections/EventsList/compact.astro +163 -0
  134. package/src/components/sections/EventsList/events.ts +168 -0
  135. package/src/components/sections/EventsList/index.astro +46 -0
  136. package/src/components/sections/EventsList/map.astro +436 -0
  137. package/src/components/sections/EventsList/shifts.astro +355 -0
  138. package/src/components/sections/EventsList/week.astro +361 -0
  139. package/src/components/sections/Faq/Contact.astro +63 -0
  140. package/src/components/sections/Faq/Questions.astro +98 -0
  141. package/src/components/sections/Faq/cards.astro +74 -0
  142. package/src/components/sections/Faq/faq.ts +101 -0
  143. package/src/components/sections/Faq/index.astro +49 -0
  144. package/src/components/sections/Faq/topics.astro +178 -0
  145. package/src/components/sections/Financials/Foot.astro +38 -0
  146. package/src/components/sections/Financials/Head.astro +47 -0
  147. package/src/components/sections/Financials/donut.astro +197 -0
  148. package/src/components/sections/Financials/financials.ts +52 -0
  149. package/src/components/sections/Financials/index.astro +148 -0
  150. package/src/components/sections/Financials/table.astro +157 -0
  151. package/src/components/sections/FormBlock/index.astro +33 -0
  152. package/src/components/sections/FormBlock/wide.astro +7 -0
  153. package/src/components/sections/Hero/cover.astro +176 -0
  154. package/src/components/sections/Hero/donate.astro +209 -0
  155. package/src/components/sections/Hero/field.astro +390 -0
  156. package/src/components/sections/Hero/index.astro +52 -0
  157. package/src/components/sections/Hero/overlap.astro +151 -0
  158. package/src/components/sections/Hero/rotating.astro +30 -0
  159. package/src/components/sections/Hero/split.astro +99 -0
  160. package/src/components/sections/Hero/statement.astro +55 -0
  161. package/src/components/sections/Hero/video.astro +399 -0
  162. package/src/components/sections/Issues/checklist.astro +204 -0
  163. package/src/components/sections/Issues/drawer.astro +237 -0
  164. package/src/components/sections/Issues/index.astro +115 -0
  165. package/src/components/sections/Issues/issues.ts +37 -0
  166. package/src/components/sections/Issues/numbered.astro +79 -0
  167. package/src/components/sections/Issues/rows.astro +137 -0
  168. package/src/components/sections/Issues/steps.astro +81 -0
  169. package/src/components/sections/Issues/tabs.astro +322 -0
  170. package/src/components/sections/Leaderboard/index.astro +29 -0
  171. package/src/components/sections/Lesson/Door.astro +121 -0
  172. package/src/components/sections/Lesson/LessonBody.astro +416 -0
  173. package/src/components/sections/Lesson/Rail.astro +182 -0
  174. package/src/components/sections/Lesson/Tracker.astro +137 -0
  175. package/src/components/sections/Lesson/index.astro +27 -0
  176. package/src/components/sections/Lesson/lesson.ts +233 -0
  177. package/src/components/sections/Lesson/reading.astro +21 -0
  178. package/src/components/sections/Map/CoverageLine.astro +19 -0
  179. package/src/components/sections/Map/RegionMap.astro +109 -0
  180. package/src/components/sections/Map/bar.astro +160 -0
  181. package/src/components/sections/Map/index.astro +192 -0
  182. package/src/components/sections/Map/map.astro +275 -0
  183. package/src/components/sections/MediaKit/BioCard.astro +108 -0
  184. package/src/components/sections/MediaKit/Downloads.astro +88 -0
  185. package/src/components/sections/MediaKit/index.astro +183 -0
  186. package/src/components/sections/MediaKit/kit.ts +140 -0
  187. package/src/components/sections/MediaKit/press.astro +189 -0
  188. package/src/components/sections/MediaKit/speaker.astro +205 -0
  189. package/src/components/sections/Membership/Benefits.astro +42 -0
  190. package/src/components/sections/Membership/Check.astro +12 -0
  191. package/src/components/sections/Membership/Price.astro +61 -0
  192. package/src/components/sections/Membership/compare.astro +312 -0
  193. package/src/components/sections/Membership/index.astro +281 -0
  194. package/src/components/sections/Membership/offers.ts +169 -0
  195. package/src/components/sections/Membership/tiers.astro +217 -0
  196. package/src/components/sections/MovementMap/index.astro +50 -0
  197. package/src/components/sections/MovementTicker/index.astro +43 -0
  198. package/src/components/sections/Pathways/Doors.astro +147 -0
  199. package/src/components/sections/Pathways/Head.astro +37 -0
  200. package/src/components/sections/Pathways/index.astro +27 -0
  201. package/src/components/sections/Pathways/pathways.ts +100 -0
  202. package/src/components/sections/Pathways/quiz.astro +286 -0
  203. package/src/components/sections/Pathways/tabs.astro +271 -0
  204. package/src/components/sections/PdfEmbed/card.astro +99 -0
  205. package/src/components/sections/PdfEmbed/index.astro +26 -0
  206. package/src/components/sections/PdfEmbed/medium.astro +7 -0
  207. package/src/components/sections/PdfEmbed/tall.astro +7 -0
  208. package/src/components/sections/Petition/coverage.astro +14 -0
  209. package/src/components/sections/Petition/image.astro +14 -0
  210. package/src/components/sections/Petition/index.astro +14 -0
  211. package/src/components/sections/Petition/map.astro +14 -0
  212. package/src/components/sections/PlatformPlanks/anchors.ts +66 -0
  213. package/src/components/sections/PlatformPlanks/columns.astro +171 -0
  214. package/src/components/sections/PlatformPlanks/index.astro +56 -0
  215. package/src/components/sections/PlatformPlanks/longread.astro +250 -0
  216. package/src/components/sections/PollBlock/index.astro +30 -0
  217. package/src/components/sections/Portfolio/featured.astro +343 -0
  218. package/src/components/sections/Portfolio/index.astro +571 -0
  219. package/src/components/sections/Portfolio/strip.astro +173 -0
  220. package/src/components/sections/Portfolio/work.ts +100 -0
  221. package/src/components/sections/Progress/MatchClock.astro +166 -0
  222. package/src/components/sections/Progress/compact.astro +150 -0
  223. package/src/components/sections/Progress/index.astro +32 -0
  224. package/src/components/sections/Progress/match.astro +126 -0
  225. package/src/components/sections/Progress/ring.astro +179 -0
  226. package/src/components/sections/QuickDonate/DonateCard.astro +149 -0
  227. package/src/components/sections/QuickDonate/Picker.astro +95 -0
  228. package/src/components/sections/QuickDonate/band.astro +164 -0
  229. package/src/components/sections/QuickDonate/bar.astro +208 -0
  230. package/src/components/sections/QuickDonate/donate.ts +126 -0
  231. package/src/components/sections/QuickDonate/hero.astro +143 -0
  232. package/src/components/sections/QuickDonate/index.astro +73 -0
  233. package/src/components/sections/QuickDonate/jar.astro +225 -0
  234. package/src/components/sections/QuickDonate/ladder.astro +248 -0
  235. package/src/components/sections/QuoteStrip/carousel.astro +340 -0
  236. package/src/components/sections/QuoteStrip/index.astro +58 -0
  237. package/src/components/sections/QuoteStrip/logos.astro +226 -0
  238. package/src/components/sections/QuoteStrip/quotes.ts +61 -0
  239. package/src/components/sections/QuoteStrip/single.astro +92 -0
  240. package/src/components/sections/QuoteStrip/ticker.astro +319 -0
  241. package/src/components/sections/QuoteStrip/wall.astro +113 -0
  242. package/src/components/sections/Resources/band.astro +93 -0
  243. package/src/components/sections/Resources/featured.astro +239 -0
  244. package/src/components/sections/Resources/index.astro +225 -0
  245. package/src/components/sections/Resources/resources.ts +92 -0
  246. package/src/components/sections/SampleBallot/Position.astro +39 -0
  247. package/src/components/sections/SampleBallot/ballot.ts +92 -0
  248. package/src/components/sections/SampleBallot/cards.astro +299 -0
  249. package/src/components/sections/SampleBallot/index.astro +326 -0
  250. package/src/components/sections/SampleBallot/measures.astro +172 -0
  251. package/src/components/sections/Scorecard/grades.astro +141 -0
  252. package/src/components/sections/Scorecard/index.astro +294 -0
  253. package/src/components/sections/Scorecard/promise.astro +167 -0
  254. package/src/components/sections/Scorecard/votes.ts +83 -0
  255. package/src/components/sections/SectionHead.astro +31 -0
  256. package/src/components/sections/Services/Button.astro +24 -0
  257. package/src/components/sections/Services/Check.astro +12 -0
  258. package/src/components/sections/Services/Includes.astro +42 -0
  259. package/src/components/sections/Services/compare.astro +328 -0
  260. package/src/components/sections/Services/index.astro +187 -0
  261. package/src/components/sections/Services/list.astro +181 -0
  262. package/src/components/sections/Services/services.ts +80 -0
  263. package/src/components/sections/ShareKit/Actions.astro +71 -0
  264. package/src/components/sections/ShareKit/Buttons.astro +62 -0
  265. package/src/components/sections/ShareKit/compact.astro +123 -0
  266. package/src/components/sections/ShareKit/index.astro +160 -0
  267. package/src/components/sections/ShareKit/share.ts +60 -0
  268. package/src/components/sections/ShareKit/strip.astro +173 -0
  269. package/src/components/sections/SignupCapture/band.astro +7 -0
  270. package/src/components/sections/SignupCapture/index.astro +103 -0
  271. package/src/components/sections/SignupCapture/inline.astro +7 -0
  272. package/src/components/sections/SocialFeed/index.astro +34 -0
  273. package/src/components/sections/StatCards/feature.astro +143 -0
  274. package/src/components/sections/StatCards/index.astro +51 -0
  275. package/src/components/sections/StatCards/ribbon.astro +113 -0
  276. package/src/components/sections/StatCards/wall.astro +177 -0
  277. package/src/components/sections/Store/featured.astro +14 -0
  278. package/src/components/sections/Store/index.astro +14 -0
  279. package/src/components/sections/Stories/Status.astro +42 -0
  280. package/src/components/sections/Stories/StoryCards.astro +171 -0
  281. package/src/components/sections/Stories/cards.astro +42 -0
  282. package/src/components/sections/Stories/index.astro +238 -0
  283. package/src/components/sections/Stories/stories.ts +97 -0
  284. package/src/components/sections/Stories/timeline.astro +135 -0
  285. package/src/components/sections/TeamGrid/board.astro +280 -0
  286. package/src/components/sections/TeamGrid/index.astro +71 -0
  287. package/src/components/sections/TeamGrid/list.astro +306 -0
  288. package/src/components/sections/TeamGrid/people.ts +178 -0
  289. package/src/components/sections/VideoEmbed/index.astro +52 -0
  290. package/src/components/sections/VideoEmbed/landscape.astro +7 -0
  291. package/src/components/sections/VideoEmbed/portrait.astro +7 -0
  292. package/src/components/sections/VideoEmbed/square.astro +7 -0
  293. package/src/components/sections/VoterTools/DaysLeft.astro +33 -0
  294. package/src/components/sections/VoterTools/Lookup.astro +43 -0
  295. package/src/components/sections/VoterTools/dates.astro +153 -0
  296. package/src/components/sections/VoterTools/index.astro +231 -0
  297. package/src/components/sections/VoterTools/polling.astro +144 -0
  298. package/src/components/sections/VoterTools/voter-tools.ts +71 -0
  299. package/src/components/sections/index.ts +373 -0
  300. package/src/components/sections/modules/Headed.astro +39 -0
  301. package/src/components/sections/modules/ModuleFrame.astro +181 -0
  302. package/src/components/store/CollectionPage.astro +40 -0
  303. package/src/components/store/ProductCard.astro +32 -0
  304. package/src/components/store/ProductGrid.astro +16 -0
  305. package/src/components/store/ProductPage.astro +146 -0
  306. package/src/components/store/StorePage.astro +137 -0
  307. package/src/components/store/StoreScript.astro +572 -0
  308. package/src/components/volunteer/ShiftLive.astro +90 -0
  309. package/src/components/volunteer/detail.astro +247 -0
  310. package/src/components/volunteer/list.astro +298 -0
  311. package/src/components/volunteer/props.ts +21 -0
  312. package/src/env.d.ts +22 -0
  313. package/src/index.d.ts +10 -0
  314. package/src/index.js +63 -0
  315. package/src/layouts/Site.astro +387 -0
  316. package/src/lib/academy.ts +146 -0
  317. package/src/lib/brand.ts +534 -0
  318. package/src/lib/chrome.ts +121 -0
  319. package/src/lib/donate-frame.ts +104 -0
  320. package/src/lib/entries.ts +190 -0
  321. package/src/lib/env.ts +34 -0
  322. package/src/lib/event-map-draw.ts +91 -0
  323. package/src/lib/events.ts +476 -0
  324. package/src/lib/fonts.ts +116 -0
  325. package/src/lib/footer.ts +24 -0
  326. package/src/lib/format.ts +160 -0
  327. package/src/lib/geo.ts +131 -0
  328. package/src/lib/live.ts +55 -0
  329. package/src/lib/menu.ts +48 -0
  330. package/src/lib/petition-text.ts +29 -0
  331. package/src/lib/reading.ts +17 -0
  332. package/src/lib/regions.ts +215 -0
  333. package/src/lib/section.ts +105 -0
  334. package/src/lib/shifts.ts +187 -0
  335. package/src/lib/store.ts +521 -0
  336. package/src/lib/stream-time.ts +20 -0
  337. package/src/lib/stream.ts +141 -0
  338. package/src/lib/visitor.ts +54 -0
  339. package/src/routes/catch-all.astro +435 -0
  340. package/src/routes/form.astro +30 -0
  341. package/src/routes/live.astro +49 -0
  342. package/src/routes/not-found.astro +18 -0
  343. package/src/routes/preview.astro +60 -0
  344. package/src/routes/setup.astro +62 -0
  345. package/src/routes/volunteer-shift.astro +61 -0
  346. package/src/styles/entries.css +784 -0
  347. package/src/styles/site.css +1910 -0
  348. package/src/styles/store.css +634 -0
  349. package/src/template.ts +182 -0
@@ -0,0 +1,387 @@
1
+ ---
2
+ // Every page's frame, as the template's template.json `chrome` and `areas`
3
+ // declare it and boards A1 (desktop) and A13 (phone) draw it:
4
+ //
5
+ // Top banner (`top_banner`) first, above the header, full width: a
6
+ // Call to action · Strip is A1's slim announcement strip,
7
+ // a TakeoverBanner fills the first screen.
8
+ // the header the layout the site chose in BackGold (`/site`
9
+ // chrome.header, one of template.json's `chrome.header`;
10
+ // src/lib/chrome.ts). `bar`: the brand (the logo, with the
11
+ // name beside it when the site asks (`showName`), else the
12
+ // template's mark and the name as a two-line wordmark) at
13
+ // the left; the header menu, each group a dropdown, its
14
+ // repeats drawn once (src/lib/menu.ts); the
15
+ // light and dark switch (ModeToggle, unless the site's
16
+ // appearance is pinned); the header button at the right.
17
+ // The template's `headerBrand` draws the brand in the kit's
18
+ // place when it has one.
19
+ // `centered`: the brand centred on a row of its own, the
20
+ // menu centred under it with the switch and the button at
21
+ // the row's right. On a phone both are the bar: the menu
22
+ // opens as a sheet under it (its groups open in place, the
23
+ // header button again full width, the social links when
24
+ // the template asks for them (`menuSheet.socials`), the
25
+ // legal line under it)
26
+ // and the button stays beside Menu in the bar until the
27
+ // sheet opens. The account links (VisitorAccount, board
28
+ // D1) sit before the switch: a signed-in visitor's first
29
+ // name and Sign out (in the sheet on a phone), else Sign
30
+ // in when the template offers it (`visitorSignIn`), naming
31
+ // the page's lesson or course to the portal's door
32
+ // (`signInTitle`); only on a first-party site, where the
33
+ // sign-in routes answer.
34
+ // On a store page (`cart`, src/lib/store.ts) the Cart
35
+ // link sits before the switch, its count of what this
36
+ // site's cart holds drawn by the store's script and the
37
+ // link hidden while it holds nothing (and with scripts
38
+ // off); it goes to the hosted checkout.
39
+ // After a sign-in, the notice "You are signed in as …"
40
+ // under the header (SignedInNotice, board D4).
41
+ // While the organization's YouTube stream is live (GET
42
+ // /live, lib/stream.ts), the menu's last item is Watch
43
+ // Live, a dot in the state red before its label, current
44
+ // on /live, in the bar and the sheet alike; nothing while
45
+ // the stream is only upcoming or the channel is off.
46
+ // the page <main>; each page renders its own single <h1>.
47
+ // other areas any area this template does not place (one the
48
+ // organization added in BackGold), after the page, full
49
+ // width, in the order BackGold lists the site's areas.
50
+ // Above the footer (`above_footer`) over the footer, full width, inside
51
+ // #above-the-footer (the newsletter issue's closing call
52
+ // links there when the area holds a sign-up). An email
53
+ // sign-up there is drawn in A1's band (SignupBand): its
54
+ // kicker and heading beside BackGold's form. It stays
55
+ // above the footer whatever the footer's layout.
56
+ // the footer the layout the site chose (`/site` chrome.footer, one
57
+ // of template.json's `chrome.footer`), with the words its
58
+ // editor in BackGold holds. `giving` (the party
59
+ // template's first): a donate strip across its top
60
+ // (DonateStrip: the footer menu's first Donate link, else
61
+ // the bottom row's, else the header button when it is
62
+ // Donate; no strip without one), the brand with its line (the footer's
63
+ // blurb, else the site's description) and social links,
64
+ // a Contact column (the address and phone) and the footer
65
+ // menu as columns (a column per group), the legal line,
66
+ // and the bottom row: the utility menu, the footer's
67
+ // legal links, the copyright line and "Powered by
68
+ // BackGold". `columns`: the same with no strip.
69
+ // `closing`: the columns under a closing call
70
+ // (ClosingCall: the headline, line, tagline and buttons
71
+ // the editor holds, over a photo when one is set; the
72
+ // template's `closingCall` in its place when it has one).
73
+ // `compact`: one row, the brand beside the social links,
74
+ // then the legal line and the bottom row. The columns'
75
+ // grid is as wide as the columns it has, so a footer with
76
+ // no menu and no contact is the brand and its line alone.
77
+ //
78
+ // The Sidebar (`sidebar`) is drawn beside the page by the routes, in
79
+ // src/routes/catch-all.astro and preview.astro, under the page's opening
80
+ // Hero when it has one. The takeover banner is the
81
+ // TakeoverBanner section an area carries (most often Top banner); it draws
82
+ // through the template's sections map like any area item.
83
+ //
84
+ // The type is the site's when it wears a saved theme in BackGold: its heading
85
+ // and body faces from `/site`'s `theme.fonts`, declared as a hosted BackGold
86
+ // page declares them (src/lib/fonts.ts). A slot the theme does not fill, and
87
+ // every slot of a site with no theme, keeps the template's own face, the one
88
+ // its boards name (`fonts` in the template's config: the party's are Fraunces
89
+ // for headings, Public Sans for text), from Google Fonts (the boards load
90
+ // them from there too). Either way the faces never block the first paint.
91
+ //
92
+ // `page` is the BackGold page being drawn as `{ id, takes_donations }`, or
93
+ // null on a route with no BackGold page (a list, an entry, an author, a
94
+ // tag, the 404); the menus apply each link's Shows on rule against it.
95
+ // Every route here passes it: left out, every link and the button show.
96
+ // `template` is the template's config (src/template.ts): its manifest, its
97
+ // sections map and its faces.
98
+ // `areas` is the response's `areas`; null draws no area.
99
+ import type { Areas } from '@backgold/content'
100
+ import { Analytics, Area, Disclaimer, MenuButton, Seo } from '@backgold/astro/components'
101
+ import { headerButtonOf, menuOf, relFor, safeHref, type MenuNode, type MenuPage } from '@backgold/astro/server'
102
+ import Brand from '../components/chrome/Brand.astro'
103
+ import ClosingCall from '../components/chrome/ClosingCall.astro'
104
+ import DonateStrip from '../components/chrome/DonateStrip.astro'
105
+ import FooterColumns from '../components/chrome/FooterColumns.astro'
106
+ import FooterContact from '../components/chrome/FooterContact.astro'
107
+ import MenuList from '../components/chrome/MenuList.astro'
108
+ import ModeToggle from '../components/chrome/ModeToggle.astro'
109
+ import SignedInNotice from '../components/chrome/SignedInNotice.astro'
110
+ import SignupBand from '../components/chrome/SignupBand.astro'
111
+ import VisitorAccount from '../components/chrome/VisitorAccount.astro'
112
+ import { appearanceOf, brandCss } from '../lib/brand'
113
+ import { chromeOf, copyrightLine } from '../lib/chrome'
114
+ import { siteFonts } from '../lib/fonts'
115
+ import { footerColumnsOf } from '../lib/footer'
116
+ import { tidyHeaderMenu } from '../lib/menu'
117
+ import { liveStream, withWatchLive } from '../lib/stream'
118
+ import type { TemplateConfig } from '../template'
119
+ import type { Checkout } from '../lib/store'
120
+ import '../styles/site.css'
121
+
122
+ interface Props {
123
+ template: TemplateConfig
124
+ title?: string
125
+ description?: string
126
+ image?: string
127
+ canonicalPath: string
128
+ noindex?: boolean
129
+ jsonLd?: object[]
130
+ page?: MenuPage | null
131
+ areas?: Areas | null
132
+ /** What the portal's sign-in door names for this page (a lesson's "Lesson 3: Read a budget, in Foundations", a course's title); none elsewhere. */
133
+ signInTitle?: string | null
134
+ /** A store page's cart: the header's Cart link to this checkout; none elsewhere. */
135
+ cart?: Checkout | null
136
+ }
137
+
138
+ /** The areas this layout (and the routes, for the Sidebar) place by name. */
139
+ const PLACED_AREAS = ['top_banner', 'sidebar', 'above_footer']
140
+
141
+ const bg = Astro.locals.backgold
142
+ if (bg.setup !== null) throw new Error('The site key is not configured; the setup page renders instead of this layout.')
143
+
144
+ const { site, legal, client } = bg
145
+ const { template, page, areas = null, signInTitle = null, cart = null, ...head } = Astro.props
146
+ const { sections } = template
147
+ const [primary, footer, utility, stream] = await Promise.all([client.menu('primary'), client.menu('footer'), client.menu('utility'), liveStream(bg)])
148
+ const pathname = Astro.url.pathname
149
+ const headerItems = primary?.items ?? []
150
+ /**
151
+ * The template's own menu links (`menuLinks`, routes it draws itself) merged
152
+ * into the header and footer menus. In the header a link sits at the top
153
+ * level, last unless `position` is `first`, and, when `group` names a group
154
+ * of the menu (by its label, case aside), first inside that group as well. In
155
+ * the footer it sits first inside its group when that group exists, else at
156
+ * the top level. A link is current on its own address and on each of `also`,
157
+ * exactly (`match` 'exact', the default, as menuOf marks a link) or there
158
+ * and under it ('prefix'). A template with none gets the menus as BackGold
159
+ * sends them.
160
+ */
161
+ const trimPath = (path: string) => (path.length > 1 ? path.replace(/\/+$/, '') : path)
162
+ function withTemplateLinks(nodes: MenuNode[], menu: 'header' | 'footer'): MenuNode[] {
163
+ const own = (template.menuLinks ?? []).filter((link) => (link.menu ?? 'header') === menu)
164
+ if (own.length === 0) return nodes
165
+ const here = trimPath(pathname)
166
+ const nodeOf = (link: (typeof own)[number]): MenuNode | null => {
167
+ const href = safeHref(link.href)
168
+ if (!href || !link.label.trim()) return null
169
+ const paths = [href, ...(link.also ?? [])].filter((p) => p.startsWith('/')).map((p) => trimPath(p.split(/[?#]/)[0]!))
170
+ const current = paths.some((p) => here === p || (link.match === 'prefix' && here.startsWith(p === '/' ? '/' : `${p}/`)))
171
+ return { label: link.label, kind: 'page', href, rel: relFor(href), current, children: [] }
172
+ }
173
+ const place = (list: MenuNode[], node: MenuNode, position: 'first' | 'last' | undefined) => (position === 'first' ? [node, ...list] : [...list, node])
174
+ const isGroup = (node: MenuNode, label: string) => node.children.length > 0 && node.label.trim().toLowerCase() === label
175
+ let out = nodes
176
+ for (const link of [...own].reverse()) {
177
+ const node = nodeOf(link)
178
+ if (!node) continue
179
+ const label = link.group?.trim().toLowerCase()
180
+ const grouped = !!label && out.some((n) => isGroup(n, label))
181
+ if (grouped) out = out.map((group) => (isGroup(group, label!) ? { ...group, children: [node, ...group.children] } : group))
182
+ }
183
+ for (const link of own) {
184
+ const node = nodeOf(link)
185
+ if (!node) continue
186
+ const label = link.group?.trim().toLowerCase()
187
+ const grouped = !!label && nodes.some((n) => isGroup(n, label))
188
+ if (menu === 'header' || !grouped) out = place(out, node, link.position)
189
+ }
190
+ return out
191
+ }
192
+ const headerButton = headerButtonOf(headerItems, pathname, page)
193
+ /**
194
+ * The header menu, its repeats drawn once (lib/menu.ts): never the header
195
+ * button again, never two same links side by side, a group of one link a
196
+ * plain item; then Watch Live last while the stream is live (lib/stream.ts).
197
+ */
198
+ const headerNodes = withWatchLive(tidyHeaderMenu(withTemplateLinks(menuOf(headerItems, pathname, page), 'header'), headerButton), stream, pathname)
199
+ const footerNodes = withTemplateLinks(menuOf(footer?.items ?? [], pathname, page), 'footer')
200
+ const bottomRow = menuOf(utility?.items ?? [], pathname, page).flatMap((node) => [node, ...node.children]).filter((node) => node.href)
201
+ const otherAreas = areas ? Object.keys(areas).filter((key) => !PLACED_AREAS.includes(key)) : []
202
+ const name = site.name ?? site.domain
203
+ /** The header and footer as the site set them up in BackGold, against what this template draws. */
204
+ const chrome = chromeOf(site, template.manifest)
205
+ /** The line under the brand in the footer: the footer's own, else the site's description. */
206
+ const description = chrome.footer.blurb ?? (site.seo.description?.trim() || null)
207
+ /** A1's social circles: the platform's short name in the circle (its first two letters when A1 names none), its full name for screen readers. */
208
+ const SHORT: Record<string, string> = { facebook: 'Fb', x: 'X', twitter: 'X', instagram: 'Ig', youtube: 'Yt' }
209
+ const social = site.social.flatMap(({ platform, url }) => {
210
+ const href = safeHref(url)
211
+ const label = platform.charAt(0).toUpperCase() + platform.slice(1)
212
+ return href ? [{ label, short: SHORT[platform.toLowerCase()] ?? label.slice(0, 2), href, rel: relFor(href) }] : []
213
+ })
214
+ /** The area map Above the footer: an email sign-up there takes A1's band. */
215
+ const aboveFooter = { ...sections, SignupCapture: SignupBand }
216
+ /** The giving footer: a donate strip across its top. */
217
+ const giving = chrome.footer.layout === 'giving'
218
+ const compact = chrome.footer.layout === 'compact'
219
+ /** The footer menu's columns, and the Contact column beside them: the grid is as wide as they are. */
220
+ const footerColumns = footerColumnsOf(footerNodes)
221
+ const hasContact = !!(chrome.footer.address || chrome.footer.phone)
222
+ const columnCount = footerColumns.length + (hasContact ? 1 : 0)
223
+ const copyright = copyrightLine(chrome.footer.copyright, name)
224
+ /** The first Donate link in a menu, groups included, that has a safe address. */
225
+ const donateIn = (nodes: MenuNode[]): MenuNode | null => {
226
+ for (const node of nodes) {
227
+ const found = node.kind === 'donate' && node.href ? node : donateIn(node.children)
228
+ if (found) return found
229
+ }
230
+ return null
231
+ }
232
+ const donateLink = giving ? (donateIn(footerNodes) ?? donateIn(bottomRow) ?? (headerButton?.kind === 'donate' ? headerButton : null)) : null
233
+ /** The footer's closing call and the header's brand: the template's own when it draws them, else the kit's. */
234
+ const Closing = template.closingCall ?? ClosingCall
235
+ const HeaderBrand = template.headerBrand ?? Brand
236
+ /** Light, dark, or auto (the visitor's system, with the header's switch). */
237
+ const appearance = appearanceOf(site.style)
238
+ /** An auto site on a template that opens dark (src/template.ts `defaultAppearance`). */
239
+ const opensDark = appearance === 'auto' && template.defaultAppearance === 'dark'
240
+ /** The account links: a signed-in visitor's always, Sign in where the template offers it; first-party sites only. */
241
+ const { visitor } = bg
242
+ const account = bg.firstParty && (visitor !== null || template.visitorSignIn === true)
243
+ /** The theme's faces, else the template's own (src/lib/fonts.ts). */
244
+ const fonts = siteFonts(site.theme, bg.firstParty, template.fonts)
245
+ ---
246
+ <!doctype html>
247
+ <html lang="en" data-gg-opens={opensDark ? 'dark' : undefined}>
248
+ <head>
249
+ <meta charset="utf-8" />
250
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
251
+ <Seo {...head} />
252
+ {fonts.preconnects.map((p) => <link rel="preconnect" href={p.href} crossorigin={p.crossorigin ? '' : undefined} />)}
253
+ {/* The template's own faces never block rendering: they arrive after first
254
+ paint (display=swap holds the fallback stack until then), and without
255
+ script they load as a plain stylesheet. */}
256
+ {fonts.stylesheet && (
257
+ <>
258
+ <link rel="stylesheet" href={fonts.stylesheet} media="print" onload="this.media='all'" />
259
+ <noscript><link rel="stylesheet" href={fonts.stylesheet} /></noscript>
260
+ </>
261
+ )}
262
+ <style is:inline set:html={brandCss(site.brand, appearance, opensDark, site.theme)}></style>
263
+ {/* The theme's faces: @font-face rules with font-display swap, so they too arrive after first paint. */}
264
+ {fonts.css && <style is:inline set:html={fonts.css}></style>}
265
+ {/* The visitor's kept choice, else the set a template that opens dark
266
+ opens in (`data-gg-opens`), as `data-gg-mode`: the switch and the
267
+ module frames, which otherwise follow the system, read it. */}
268
+ {appearance === 'auto' && (
269
+ <script is:inline>
270
+ ;(function () {
271
+ var root = document.documentElement
272
+ var mode = null
273
+ try {
274
+ mode = localStorage.getItem('gg-mode')
275
+ } catch (e) {}
276
+ if (mode !== 'dark' && mode !== 'light') mode = root.getAttribute('data-gg-opens')
277
+ if (mode === 'dark' || mode === 'light') root.setAttribute('data-gg-mode', mode)
278
+ })()
279
+ </script>
280
+ )}
281
+ </head>
282
+ <body>
283
+ <a class="skip-link" href="#main">Skip to content</a>
284
+ <Area name="top_banner" areas={areas} components={sections} />
285
+ <header class="site-header" data-layout={chrome.header.layout}>
286
+ <div class="site-header-inner">
287
+ <HeaderBrand name={name} logoUrl={site.brand.logo_url} showName={chrome.header.showName} />
288
+ {headerNodes.length > 0 && (
289
+ <>
290
+ <nav class="header-bar-menu" aria-label="Header menu">
291
+ <MenuList nodes={headerNodes} mode="bar" />
292
+ </nav>
293
+ <details class="header-sheet">
294
+ <summary><span class="sheet-open">Menu</span><span class="sheet-close">Close</span></summary>
295
+ <div class="header-sheet-panel">
296
+ <nav aria-label="Header menu">
297
+ <MenuList nodes={headerNodes} mode="sheet" />
298
+ </nav>
299
+ <MenuButton items={headerItems} page={page} class="button header-sheet-button" />
300
+ {account && <VisitorAccount visitor={visitor} mode="sheet" />}
301
+ {template.menuSheet?.socials && social.length > 0 && (
302
+ <ul class="social header-sheet-social" aria-label="Social media">
303
+ {social.map((s) => <li><a href={s.href} rel={s.rel} aria-label={s.label}>{s.short}</a></li>)}
304
+ </ul>
305
+ )}
306
+ <div class="header-sheet-legal"><Disclaimer legal={legal} /></div>
307
+ </div>
308
+ </details>
309
+ </>
310
+ )}
311
+ {account && <VisitorAccount visitor={visitor} mode="bar" signInTitle={signInTitle} />}
312
+ {cart && (
313
+ <a class="cart-link" href={cart.url} data-bg-cart={cart.org} data-bg-checkout={cart.url} hidden>
314
+ <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M3 4h2l2.5 11h11L21 8H6.5" /><circle cx="9" cy="19" r="1.5" /><circle cx="17" cy="19" r="1.5" /></svg>
315
+ <span>Cart</span>
316
+ <span class="cart-count" data-bg-cart-count>0</span>
317
+ </a>
318
+ )}
319
+ {appearance === 'auto' && <ModeToggle />}
320
+ <MenuButton items={headerItems} page={page} class="button button-small header-button" />
321
+ </div>
322
+ </header>
323
+ {visitor && <SignedInNotice visitor={visitor} domain={new URL(bg.siteUrl).host} />}
324
+
325
+ <main id="main" tabindex="-1">
326
+ <slot />
327
+ </main>
328
+
329
+ {otherAreas.map((key) => <Area name={key} areas={areas} components={sections} class="bg-area-after-page" />)}
330
+ <div id="above-the-footer">
331
+ <Area name="above_footer" areas={areas} components={aboveFooter} />
332
+ </div>
333
+ <footer class="site-footer" data-layout={chrome.footer.layout}>
334
+ {chrome.footer.closing && <Closing call={chrome.footer.closing} />}
335
+ <div class="site-footer-inner">
336
+ {giving && <DonateStrip link={donateLink} />}
337
+ {compact ? (
338
+ <div class="footer-compact">
339
+ <Brand name={name} logoUrl={site.brand.logo_url} />
340
+ {social.length > 0 && (
341
+ <ul class="social" aria-label="Social media">
342
+ {social.map((s) => <li><a href={s.href} rel={s.rel} aria-label={s.label}>{s.short}</a></li>)}
343
+ </ul>
344
+ )}
345
+ </div>
346
+ ) : (
347
+ <div class="footer-grid" style={`--footer-columns: ${columnCount}`}>
348
+ <div class="footer-brand">
349
+ <Brand name={name} logoUrl={site.brand.logo_url} />
350
+ {description && <p class="footer-description">{description}</p>}
351
+ {social.length > 0 && (
352
+ <ul class="social" aria-label="Social media">
353
+ {social.map((s) => <li><a href={s.href} rel={s.rel} aria-label={s.label}>{s.short}</a></li>)}
354
+ </ul>
355
+ )}
356
+ </div>
357
+ <FooterContact address={chrome.footer.address} phone={chrome.footer.phone} />
358
+ <FooterColumns columns={footerColumns} />
359
+ </div>
360
+ )}
361
+ {/*
362
+ The legal line ("Paid for by …") must appear on every page, as text in
363
+ the HTML the server sends. It is required by law, and BackGold checks
364
+ the live home page for it every hour and warns the organization when
365
+ it is missing. Restyle it freely; do not remove it, split it or render
366
+ it with client-side script.
367
+ */}
368
+ <div class="disclaimer">
369
+ <Disclaimer legal={legal} />
370
+ </div>
371
+ <div class="footer-row">
372
+ {(bottomRow.length > 0 || chrome.footer.legalLinks.length > 0) && (
373
+ <nav aria-label="Bottom row">
374
+ <ul>
375
+ {bottomRow.map((node) => <li><a href={node.href} rel={node.rel} aria-current={node.current ? 'page' : undefined}>{node.label}</a></li>)}
376
+ {chrome.footer.legalLinks.map((link) => <li><a href={link.href} rel={link.rel}>{link.label}</a></li>)}
377
+ </ul>
378
+ </nav>
379
+ )}
380
+ <span class="footer-copyright">{copyright}</span>
381
+ <a class="footer-powered" href="https://backgold.com">Powered by BackGold</a>
382
+ </div>
383
+ </div>
384
+ </footer>
385
+ <Analytics />
386
+ </body>
387
+ </html>
@@ -0,0 +1,146 @@
1
+ // The academy's words and numbers, as boards D1 (Classroom), D2 (Course) and
2
+ // D3 (Lesson) of docs/design/academy-2026-10 print them: a lesson's length
3
+ // ("4:50"), a course's ("1 h 1 min"), the lesson count, the progress
4
+ // phrases, who can watch, and the doors' links. Every number comes from the
5
+ // Content API; none is typed by the organization.
6
+
7
+ import type { ContentAccessLevel, CourseProgress, EntryLock, LessonResponse } from '#contract/content-api'
8
+
9
+ /** The built-in content type the courses are. */
10
+ export const COURSE_TYPE_KEY = 'course'
11
+
12
+ /** The site's Join page (the members door's "See how to join") and its Contact page (the tag door's). */
13
+ export const JOIN_PATH = '/join'
14
+ export const CONTACT_PATH = '/contact'
15
+
16
+ /**
17
+ * What the portal's sign-in door names for a lesson: "Lesson 3: Read a
18
+ * budget, in Foundations" (its place in the course by position, 1 when it is
19
+ * not in the course's list).
20
+ */
21
+ export function lessonSignInTitle(answer: LessonResponse): string {
22
+ const lessons = [...answer.course.lessons].sort((a, b) => a.position - b.position)
23
+ const n = lessons.findIndex((l) => l.slug === answer.lesson.slug) + 1 || 1
24
+ return `Lesson ${n}: ${answer.lesson.title}, in ${answer.course.title}`
25
+ }
26
+
27
+ /** The Content API's access levels (CONTENT_ACCESS_LEVELS in the platform's constants). */
28
+ const ACCESS_LEVELS: readonly ContentAccessLevel[] = ['public', 'signed_in', 'members', 'tag']
29
+
30
+ /** A row's `access` as the Content API names it. */
31
+ export const isAccess = (value: unknown): value is ContentAccessLevel => (ACCESS_LEVELS as readonly unknown[]).includes(value)
32
+
33
+ const whole = (value: unknown): number | null => (typeof value === 'number' && Number.isFinite(value) && value >= 0 ? Math.round(value) : null)
34
+
35
+ /** A lesson's length as a clock: "4:50", "1:02:05"; null without one. */
36
+ export function clockOf(seconds: unknown): string | null {
37
+ const s = whole(seconds)
38
+ if (s === null) return null
39
+ const h = Math.floor(s / 3600)
40
+ const m = Math.floor((s % 3600) / 60)
41
+ const pad = (n: number) => String(n).padStart(2, '0')
42
+ return h > 0 ? `${h}:${pad(m)}:${pad(s % 60)}` : `${m}:${pad(s % 60)}`
43
+ }
44
+
45
+ /** A course's length in words: "1 h 1 min", "52 min"; null without one. */
46
+ export function lengthOf(seconds: unknown): string | null {
47
+ const s = whole(seconds)
48
+ if (s === null || s === 0) return null
49
+ const minutes = Math.max(1, Math.round(s / 60))
50
+ const h = Math.floor(minutes / 60)
51
+ const m = minutes % 60
52
+ if (h === 0) return `${m} min`
53
+ return m === 0 ? `${h} h` : `${h} h ${m} min`
54
+ }
55
+
56
+ /** "12 lessons", "1 lesson". */
57
+ export const lessonsOf = (count: number): string => `${count} ${count === 1 ? 'lesson' : 'lessons'}`
58
+
59
+ /** "12 lessons · 1 h 1 min", or the count alone when no lesson carries a length. */
60
+ export function countAndLength(count: number, seconds: number | null): string {
61
+ const length = lengthOf(seconds)
62
+ return length ? `${lessonsOf(count)} · ${length}` : lessonsOf(count)
63
+ }
64
+
65
+ export type CourseState = 'new' | 'started' | 'finished'
66
+
67
+ /** Where a visitor stands in a course: finished means every lesson they can open (ruling 10). */
68
+ export function stateOf(progress: CourseProgress): CourseState {
69
+ if (progress.openable > 0 && progress.completed >= progress.openable) return 'finished'
70
+ return progress.completed > 0 ? 'started' : 'new'
71
+ }
72
+
73
+ /** "38 min left", or null when no unfinished lesson carries a length. */
74
+ export function leftOf(progress: CourseProgress): string | null {
75
+ const length = lengthOf(progress.seconds_left)
76
+ return length ? `${length} left` : null
77
+ }
78
+
79
+ /**
80
+ * Who can watch, as D2's About this course words it: "Anyone", "Anyone
81
+ * signed in with their email", "Members of <org>", "People in <tag>".
82
+ */
83
+ export function whoCanWatch(access: ContentAccessLevel, orgName: string | null, tag: string | null): string {
84
+ switch (access) {
85
+ case 'public':
86
+ return 'Anyone'
87
+ case 'signed_in':
88
+ return 'Anyone signed in with their email'
89
+ case 'members':
90
+ return orgName ? `Members of ${orgName}` : 'Members'
91
+ case 'tag':
92
+ return tag ? `People in ${tag}` : 'People the organization invites'
93
+ }
94
+ }
95
+
96
+ /** A signed-out card's chip: what it takes to watch. */
97
+ export function accessChipOf(access: ContentAccessLevel, tag: string | null): string {
98
+ switch (access) {
99
+ case 'public':
100
+ return 'Free'
101
+ case 'signed_in':
102
+ return 'Free with your email'
103
+ case 'members':
104
+ return 'For members'
105
+ case 'tag':
106
+ return tag ? `For ${tag} members` : 'By invitation'
107
+ }
108
+ }
109
+
110
+ /** A lock's word on a syllabus row or a cover: "For members", "For Fall Cohort members", "Sign in to watch". */
111
+ export function lockWordOf(lock: EntryLock): string {
112
+ if (lock.reason === 'members') return 'For members'
113
+ if (lock.reason === 'tag') return lock.tag_label ? `For ${lock.tag_label} members` : 'By invitation'
114
+ return 'Sign in to watch'
115
+ }
116
+
117
+ /** "Lesson 5: Decide what you want". */
118
+ export const lessonTitle = (n: number, title: string): string => `Lesson ${n}: ${title}`
119
+
120
+ /** "the Harbor letter", from the heading "The Harbor letter"; the article lowered to sit inside a sentence. */
121
+ export function inSentence(name: string): string {
122
+ const trimmed = name.trim()
123
+ return /^the\s/i.test(trimmed) ? `the ${trimmed.slice(4)}` : `the ${trimmed}`
124
+ }
125
+
126
+ const WEEKDAYS = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
127
+ const MONTHS = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
128
+ const DAY_MS = 24 * 60 * 60 * 1000
129
+
130
+ /**
131
+ * When a lesson was finished, as D2's course head says it after "Lesson 4
132
+ * finished": "today", "yesterday", "on Tuesday" within the week, else "on
133
+ * October 3" (and the year when it is not this one). Days are UTC days: the
134
+ * site has no zone of its own. Null for a time that does not parse.
135
+ */
136
+ export function finishedOn(iso: string, now: Date = new Date()): string | null {
137
+ const at = new Date(iso)
138
+ if (Number.isNaN(at.getTime())) return null
139
+ const day = (d: Date) => Math.floor(d.getTime() / DAY_MS)
140
+ const ago = day(now) - day(at)
141
+ if (ago <= 0) return 'today'
142
+ if (ago === 1) return 'yesterday'
143
+ if (ago < 7) return `on ${WEEKDAYS[at.getUTCDay()]}`
144
+ const date = `${MONTHS[at.getUTCMonth()]} ${at.getUTCDate()}`
145
+ return at.getUTCFullYear() === now.getUTCFullYear() ? `on ${date}` : `on ${date}, ${at.getUTCFullYear()}`
146
+ }