@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,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
+ }
@@ -0,0 +1,435 @@
1
+ ---
2
+ // Every address on the site. resolveRoute reads what the path is from
3
+ // BackGold (a page, a type's list, an entry, an author, a term, a feed), so
4
+ // a content type the organization adds gets its pages with no change here.
5
+ // Redirects were already answered by the middleware.
6
+ //
7
+ // An entry is drawn by its type's entry layout and a list (a type's list, or
8
+ // a term's) by its type's list layout, as the template's template.json
9
+ // `entryLayouts` names them (src/components/entries); a type it does not name, and the
10
+ // news list (the blog types' shared list at the organization's blog base,
11
+ // `/news` for one made since the address became its own, `/blog` for one that
12
+ // kept it), use the post layouts. A list shows
13
+ // one page of up to 50 entries: `?cursor=` asks for a later one, and the
14
+ // layout draws "Older" on to the next page and "Newest" back to the first
15
+ // (the api names no previous page, so there is no "Newer").
16
+ //
17
+ // The news list opens with its intro when a published page sits at its
18
+ // address (resolveRoute's `intro`; the starter's `news` page, board A4): that
19
+ // page's sections, its Hero's headline the one <h1>, above the list. Such a
20
+ // page is the list's opening, never a page of its own.
21
+ //
22
+ // The news list and its terms' lists carry a search box that sends `?q=` to
23
+ // the news list. There a search of 2 to 80 characters lists the matching
24
+ // posts (the Content API's `?q=`, at most 20 a type) in place of the list,
25
+ // with no pager; anything else under `q` shows the list. A response to a
26
+ // request with `q` is never stored: the edge cache keys a list by its cursor
27
+ // alone, so a stored search would answer the bare list's address. Neither is
28
+ // a response with a calendar's `?month=`, nor a page with a calendar section
29
+ // at all: the month it shows and its today move with the clock.
30
+ //
31
+ // A page that draws a Donate frame (a section or an area item of type Donate)
32
+ // names the donate query names its frame copies (READS_QUERY_HEADER,
33
+ // lib/donate-frame.ts), so the edge cache never answers `?amount=25` with
34
+ // the bare page's copy, and a request that carries one is never stored. A
35
+ // page that draws a form frame names `pick`, the choice the form opens on,
36
+ // the same way.
37
+ //
38
+ // `/events/<type>` is the events page with its Agenda and Calendar sections
39
+ // narrowed to that type (the Agenda's rows read from the Content API's `GET
40
+ // /events?type=`, src/lib/events.ts; the Calendar reads its month by type
41
+ // itself), when the path is not already a page or an entry; a type with no upcoming event, or
42
+ // one that does not exist, is a 404; it answers `X-BackGold-Page` with the
43
+ // events page's id (drawnInstead). Any other `/events/<slug>` that is not
44
+ // a page or an entry is that event's own page (the template's `eventPage`,
45
+ // else src/components/EventPage.astro), read from `GET /events/<slug>`; a slug the api has no event for is a 404. A
46
+ // type's tab wins over an event slugged like the type while the type has an
47
+ // upcoming event. `/events.ics` is every upcoming event as one calendar file
48
+ // and `/events/<slug>.ics` one event's (src/lib/events.ts).
49
+ //
50
+ // The store (src/lib/store.ts, board 06 of the store design) is answered
51
+ // from the Content API's catalog reads when resolveRoute finds nothing at
52
+ // the address: `/store/<slug>` is a listing's page (GET /products/<slug>),
53
+ // `/store/departments/<slug>` a department's shelf (its `?attr=` filters
54
+ // passed to GET /products, its stored copy never answering a filtered
55
+ // address, which is never stored) and `/collections/<slug>`
56
+ // a collection's page (GET /collections/<slug>; the api's /types leaves the
57
+ // `collection` type out, so resolveRoute never answers it as an entry).
58
+ // `/store` is the shop (GET /products) whenever the organization has a
59
+ // published listing: a published page at /store becomes the shop's opening
60
+ // (its sections above the grid, a Store section among them left out), and
61
+ // with no listing that page is drawn as it is. A slug the api has no answer
62
+ // for, and every store address on an api older than the catalog, is a 404.
63
+ // Each store page carries the header's Cart link and the store script
64
+ // (components/store/StoreScript.astro); a listing's page also carries its
65
+ // island. Their areas are the page's at /store (else those of a page that
66
+ // holds the store, GET /areas?holds=store), the listing's and the
67
+ // collection's own; a Sidebar item draws under the page, full width.
68
+ //
69
+ // A lesson, `/<courses base>/<course>/<lesson>`, is the video read through
70
+ // its course (resolveRoute's `lesson`): drawn by the template's `course:lesson`
71
+ // entry layout (lessonLayoutFor; the kit's Lesson player when the template
72
+ // registers none), given the lesson as `entry` and the api's whole answer
73
+ // (the course, the lessons either side) as `lesson`. The course's list and its own page are the
74
+ // course type's list and entry layouts. Every read here is made for the
75
+ // signed-in visitor when there is one (`locals.backgold.visitorReads`), so
76
+ // their locks open; their pages are never cached (the middleware).
77
+ //
78
+ // A page passes itself to the layout as `{ id, takes_donations }`, so the
79
+ // menus apply each link's Shows on rule; every other route passes null. A
80
+ // page, an entry, a list, a term and an event pass their areas to the layout
81
+ // (Top banner and Above the footer). A page, an entry, a list and a term
82
+ // draw their Sidebar beside the main column when it has an item (under it on
83
+ // a phone); with none they are one column. A page that opens with a Hero
84
+ // puts the Hero over both columns, so the Sidebar starts under it, beside
85
+ // what follows (board C5). An event has no column beside it: its Sidebar
86
+ // items draw under the event, full width (board C6's "More chances").
87
+ import type { Areas } from '@backgold/content'
88
+ import { Area } from '@backgold/astro/components'
89
+ import { READS_QUERY_HEADER, areaEntriesOf, atomFeed, drawnInstead, jsonLdFor, pagerOf, relFor, resolveRoute, safeHref, safeSrc, type MenuPage, type Resolved } from '@backgold/astro/server'
90
+ import Site from '../layouts/Site.astro'
91
+ import EntryCard from '../components/EntryCard.astro'
92
+ import EventPage from '../components/EventPage.astro'
93
+ import NotFound from '../components/NotFound.astro'
94
+ import PageSections from '../components/PageSections.astro'
95
+ import { entryLayoutFor, lessonLayoutFor, listLayoutFor, volunteerLayoutFor } from '../components/entries'
96
+ import type { ListLayoutProps } from '../components/entries/props'
97
+ import { basePath, filterOf, listName, searchNews, searchQuery } from '../lib/entries'
98
+ import { EVENTS_CALENDAR_PATH, MONTH_PARAM, calendarSlugOf, drawsCalendar, eventCalendar, eventPage, eventsCalendar, typedEventsPage } from '../lib/events'
99
+ import { entryCard, leadsWithHero } from '../lib/section'
100
+ import { DONATE_READS_QUERY, FORM_READS_QUERY, carriesDonateQuery, carriesPickQuery, drawsDonateFrame, drawsFormFrame } from '../lib/donate-frame'
101
+ import { VOLUNTEER_PATH, openShifts, volunteerAreas } from '../lib/shifts'
102
+ import { markReading } from '../lib/reading'
103
+ import { COURSE_TYPE_KEY, lessonSignInTitle } from '../lib/academy'
104
+ import { FILTER_PARAM, checkoutFor, collectionPage, departmentOf, filteredPath, productJsonLd, productPage, storeFiltersOf, storeRouteOf, storefront, type Checkout, type StoreFilters } from '../lib/store'
105
+ import StorePage from '../components/store/StorePage.astro'
106
+ import ProductPage from '../components/store/ProductPage.astro'
107
+ import CollectionPage from '../components/store/CollectionPage.astro'
108
+ import StoreScript from '../components/store/StoreScript.astro'
109
+ import type { CollectionDetail, PageResponse, ProductDepartment, ProductDetail, ProductsResponse } from '@backgold/content'
110
+ import template from 'virtual:backgold-template'
111
+
112
+ const { sections } = template
113
+ // Every component this request draws reads the template here (ModuleFrame's frame options, LeadingHero's sections), areas and event pages included.
114
+ Astro.locals.template = template
115
+ /** One event's page and the 404's content: the template's own when it draws them, else the kit's. */
116
+ const EventLayout = template.eventPage ?? EventPage
117
+ const NotFoundLayout = template.notFound ?? NotFound
118
+
119
+ const bg = Astro.locals.backgold
120
+ if (bg.setup !== null) return new Response(null, { status: 503 })
121
+
122
+ const { client, site, siteUrl, visitorReads } = bg
123
+ const siteName = site.name ?? site.domain
124
+ const pathname = Astro.url.pathname
125
+ // `/events.ics` is every upcoming event as one calendar file (the events
126
+ // list's "Add every event to your calendar").
127
+ if (pathname === EVENTS_CALENDAR_PATH) {
128
+ const file = await eventsCalendar(client, siteUrl, `${siteName} events`)
129
+ if (!file) return new Response('Not found', { status: 404 })
130
+ return new Response(file, {
131
+ headers: { 'Content-Type': 'text/calendar; charset=utf-8', 'Content-Disposition': 'attachment; filename="events.ics"' },
132
+ })
133
+ }
134
+ // `/events/<slug>.ics` is the event's calendar file (its page's Add to calendar).
135
+ const calendarSlug = calendarSlugOf(pathname)
136
+ if (calendarSlug !== null) {
137
+ const found = await eventPage(client, `/events/${encodeURIComponent(calendarSlug)}`)
138
+ const file = found ? eventCalendar(found.event, new URL(`/events/${encodeURIComponent(found.event.slug)}`, siteUrl).toString(), new URL(siteUrl).host) : null
139
+ if (!file) return new Response('Not found', { status: 404 })
140
+ return new Response(file, {
141
+ headers: { 'Content-Type': 'text/calendar; charset=utf-8', 'Content-Disposition': `attachment; filename="${found!.event.slug}.ics"` },
142
+ })
143
+ }
144
+ // The URL, not just the path: a list's `?cursor=` asks for a later page.
145
+ let resolved: Resolved = await resolveRoute(client, Astro.url, visitorReads)
146
+ // The store's pages (above): what the address is, and what the api answered for it.
147
+ type StoreView =
148
+ | { kind: 'store'; shop: ProductsResponse; department: ProductDepartment | null; intro: PageResponse | null; cursor: string | null; filters: StoreFilters }
149
+ | { kind: 'product'; product: ProductDetail; areas: Areas }
150
+ | { kind: 'collection'; collection: CollectionDetail; areas: Areas }
151
+ const storeRoute = storeRouteOf(pathname)
152
+ let store: StoreView | null = null
153
+ if (storeRoute?.kind === 'store' && (resolved.kind === 'not_found' || (resolved.kind === 'page' && storeRoute.department === null))) {
154
+ const cursor = Astro.url.searchParams.get('cursor') || null
155
+ // Only a department's page is filtered: the shop's root has no facets.
156
+ const filters = storeRoute.department === null ? [] : storeFiltersOf(Astro.url.searchParams)
157
+ const read = await storefront(client, { department: storeRoute.department, cursor, filters })
158
+ const shop = read?.shop ?? null
159
+ const department = shop ? departmentOf(shop.departments, storeRoute.department) : null
160
+ const open = shop !== null && (storeRoute.department === null ? shop.products.length > 0 || cursor !== null : department !== null)
161
+ if (open) store = { kind: 'store', shop: shop!, department, intro: resolved.kind === 'page' ? resolved.page : null, cursor, filters: read!.filters }
162
+ } else if (storeRoute?.kind === 'product' && resolved.kind === 'not_found') {
163
+ const found = await productPage(client, storeRoute.slug)
164
+ if (found) store = { kind: 'product', product: found.product, areas: found.areas }
165
+ } else if (storeRoute?.kind === 'collection' && resolved.kind === 'not_found') {
166
+ const found = await collectionPage(client, storeRoute.slug)
167
+ if (found) store = { kind: 'collection', collection: found.collection, areas: found.areas }
168
+ }
169
+ /** Where the store's cart checks out: read off the listings the page shows. */
170
+ const checkout: Checkout | null =
171
+ store?.kind === 'store'
172
+ ? checkoutFor(store.shop.products)
173
+ : store?.kind === 'product'
174
+ ? checkoutFor([store.product, ...store.product.related])
175
+ : store?.kind === 'collection'
176
+ ? checkoutFor(store.collection.products)
177
+ : null
178
+ /** A page of the shop past the first, and the next one's address. */
179
+ const storePager =
180
+ store?.kind === 'store'
181
+ ? {
182
+ more: store.shop.next_cursor ? filteredPath(pathname.replace(/\/+$/, ''), store.filters, store.shop.next_cursor) : null,
183
+ first: store.cursor ? filteredPath(pathname.replace(/\/+$/, ''), store.filters) : null,
184
+ }
185
+ : { more: null, first: null }
186
+ const storeAreas: Areas | null =
187
+ store?.kind === 'product'
188
+ ? store.areas
189
+ : store?.kind === 'collection'
190
+ ? store.areas
191
+ : store?.kind === 'store'
192
+ ? (store.intro?.areas ?? (await client.areas({ holds: ['store'] }).then((a) => a.areas, () => null)))
193
+ : null
194
+
195
+ const typed = resolved.kind === 'not_found' && !store ? await typedEventsPage(client, Astro.request, pathname) : null
196
+ if (typed) {
197
+ resolved = { kind: 'page', page: typed.page }
198
+ drawnInstead(resolved)
199
+ }
200
+ const event = resolved.kind === 'not_found' && !store ? await eventPage(client, pathname) : null
201
+ // `/volunteer` with no page of the site's own at that address is the kit's
202
+ // open-shifts list (lib/shifts.ts); a published Volunteer page there, the
203
+ // candidate starter's among them, is the page.
204
+ const volunteerList = resolved.kind === 'not_found' && !event && pathname === VOLUNTEER_PATH
205
+ const shifts = volunteerList ? await openShifts(client) : null
206
+ const rawQuery = Astro.url.searchParams.get('q')
207
+ const calendar = Astro.url.searchParams.has(MONTH_PARAM) || (resolved.kind === 'page' && resolved.page.sections.some(drawsCalendar))
208
+ if (rawQuery !== null || calendar) Astro.response.headers.set('Cache-Control', 'no-store')
209
+
210
+ if (resolved.kind === 'feed') {
211
+ return new Response(await atomFeed(client, siteUrl, resolved.type), {
212
+ headers: { 'Content-Type': 'application/atom+xml; charset=utf-8' },
213
+ })
214
+ }
215
+ if (resolved.kind === 'not_found' && !event && !volunteerList && !store) Astro.response.status = 404
216
+
217
+ let head: { title?: string; description?: string; image?: string; canonicalPath: string; noindex?: boolean; jsonLd?: object[] }
218
+ switch (resolved.kind) {
219
+ case 'page': {
220
+ const { page, sections } = resolved.page
221
+ const firstImage = sections.flatMap((s) => Object.values(s.media ?? {})).map((m) => safeSrc(m.url)).find((u) => u !== null)
222
+ const title = page.meta.title ?? page.title ?? undefined
223
+ head = {
224
+ title: typed && title ? `${typed.type.label} · ${title}` : title,
225
+ description: page.meta.description ?? undefined,
226
+ image: safeSrc(page.meta.image_url) ?? firstImage ?? undefined,
227
+ canonicalPath: typed ? pathname : page.url,
228
+ jsonLd: jsonLdFor({ site, siteUrl, kind: 'page', page }),
229
+ }
230
+ break
231
+ }
232
+ case 'index':
233
+ head = {
234
+ title: `${listName(resolved.type, resolved.base, resolved.intro)} · ${siteName}`,
235
+ canonicalPath: pathname,
236
+ jsonLd: jsonLdFor({ site, siteUrl, kind: 'index', type: resolved.type, base: resolved.base, intro: resolved.intro }),
237
+ }
238
+ break
239
+ case 'entry': {
240
+ const { entry, type } = resolved
241
+ head = {
242
+ title: entry.title,
243
+ description: entry.summary ?? undefined,
244
+ image: entry.hero ? (safeSrc(entry.hero.url) ?? undefined) : undefined,
245
+ canonicalPath: entry.url ?? pathname,
246
+ jsonLd: jsonLdFor({ site, siteUrl, kind: 'entry', type, entry }),
247
+ }
248
+ break
249
+ }
250
+ case 'lesson': {
251
+ const { lesson, course } = resolved.lesson
252
+ head = {
253
+ title: `${lesson.title} · ${course.title}`,
254
+ description: lesson.summary ?? undefined,
255
+ image: lesson.hero ? (safeSrc(lesson.hero.url) ?? undefined) : undefined,
256
+ canonicalPath: pathname,
257
+ }
258
+ break
259
+ }
260
+ case 'author':
261
+ head = {
262
+ title: `${resolved.author.display_name} · ${siteName}`,
263
+ description: resolved.author.bio ?? undefined,
264
+ canonicalPath: pathname,
265
+ jsonLd: jsonLdFor({ site, siteUrl, kind: 'author', author: resolved.author }),
266
+ }
267
+ break
268
+ case 'term':
269
+ head = {
270
+ title: `${resolved.term.label} · ${siteName}`,
271
+ canonicalPath: pathname,
272
+ jsonLd: jsonLdFor({ site, siteUrl, kind: 'term', type: resolved.type, base: resolved.base, taxonomy: resolved.taxonomy, term: resolved.term }),
273
+ }
274
+ break
275
+ default:
276
+ head = event
277
+ ? { title: `${event.event.title} · ${siteName}`, image: safeSrc(event.event.image_url) ?? undefined, canonicalPath: pathname }
278
+ : volunteerList
279
+ ? { title: `Volunteer · ${siteName}`, description: `Open volunteer shifts with ${siteName}.`, canonicalPath: VOLUNTEER_PATH }
280
+ : { title: `Page not found · ${siteName}`, canonicalPath: pathname, noindex: true }
281
+ }
282
+ if (store?.kind === 'store') {
283
+ const intro = store.intro
284
+ const title = store.department ? store.department.label : (intro?.page.meta.title ?? intro?.page.title ?? 'Store')
285
+ head = {
286
+ title: `${title} · ${siteName}`,
287
+ description: intro?.page.meta.description ?? `Everything in the ${siteName} store.`,
288
+ image: safeSrc(intro?.page.meta.image_url) ?? safeSrc(store.shop.products[0]?.photos[0]?.url) ?? undefined,
289
+ canonicalPath: pathname.replace(/\/+$/, '') || '/',
290
+ ...(intro ? { jsonLd: jsonLdFor({ site, siteUrl, kind: 'page', page: intro.page }) } : {}),
291
+ }
292
+ } else if (store?.kind === 'product') {
293
+ const { product } = store
294
+ head = {
295
+ title: `${product.seo.title} · ${siteName}`,
296
+ description: product.seo.description ?? undefined,
297
+ image: safeSrc(product.seo.image_url) ?? undefined,
298
+ canonicalPath: pathname,
299
+ jsonLd: [productJsonLd(product, siteUrl)],
300
+ }
301
+ } else if (store?.kind === 'collection') {
302
+ const { collection } = store
303
+ head = {
304
+ title: `${collection.title} · ${siteName}`,
305
+ description: collection.intro ?? undefined,
306
+ image: safeSrc(collection.cover?.url) ?? undefined,
307
+ canonicalPath: pathname,
308
+ }
309
+ }
310
+ const menuPage: MenuPage | null =
311
+ store?.kind === 'store' && store.intro
312
+ ? { id: store.intro.page.id, takes_donations: store.intro.page.takes_donations }
313
+ : store
314
+ ? null
315
+ : resolved.kind === 'page'
316
+ ? { id: resolved.page.page.id, takes_donations: resolved.page.page.takes_donations }
317
+ : null
318
+ const areas: Areas | null = store ? storeAreas :
319
+ resolved.kind === 'page'
320
+ ? resolved.page.areas
321
+ : resolved.kind === 'entry' || resolved.kind === 'index' || resolved.kind === 'term' || resolved.kind === 'lesson'
322
+ ? resolved.areas
323
+ : volunteerList
324
+ ? await volunteerAreas(client)
325
+ : event?.areas ?? null
326
+ {
327
+ const pageSections = resolved.kind === 'page' ? resolved.page.sections : []
328
+ // A department's page reads its filters (`?attr=`), a name the edge
329
+ // cache's key leaves out: its stored copy is never served to a filtered
330
+ // address, and a filtered page is never stored.
331
+ const filtersRead = store?.kind === 'store' && store.department !== null
332
+ const reads = [
333
+ ...(drawsDonateFrame(pageSections, areas) ? [DONATE_READS_QUERY] : []),
334
+ ...(drawsFormFrame(pageSections, areas) ? [FORM_READS_QUERY] : []),
335
+ ...(filtersRead ? [FILTER_PARAM] : []),
336
+ ]
337
+ if (reads.length > 0) {
338
+ Astro.response.headers.set(READS_QUERY_HEADER, reads.join(','))
339
+ const carries =
340
+ (drawsDonateFrame(pageSections, areas) && carriesDonateQuery(Astro.url.searchParams)) ||
341
+ (drawsFormFrame(pageSections, areas) && carriesPickQuery(Astro.url.searchParams)) ||
342
+ (filtersRead && Astro.url.searchParams.has(FILTER_PARAM))
343
+ if (carries) Astro.response.headers.set('Cache-Control', 'no-store')
344
+ }
345
+ }
346
+ // The sections in an entry's areas leave out the entry being read (lib/reading.ts).
347
+ if (resolved.kind === 'entry') markReading(Astro.locals, resolved.entry.id)
348
+ if (resolved.kind === 'lesson') markReading(Astro.locals, resolved.lesson.lesson.id)
349
+ const sidebar = !store && resolved.kind !== 'author' && resolved.kind !== 'not_found' && areaEntriesOf(areas, 'sidebar').length > 0
350
+ const storeMore = store !== null && areaEntriesOf(areas, 'sidebar').length > 0
351
+ const heroOverSplit = sidebar && resolved.kind === 'page' && leadsWithHero(resolved.page.sections)
352
+ const eventMore = event !== null && areaEntriesOf(event.areas, 'sidebar').length > 0
353
+
354
+ // A list, or a term's list: its layout and what it is given. The filter comes
355
+ // from the type's whole first page, so every term with an entry on it stays
356
+ // offered while one is chosen, on every later page and beside a search.
357
+ let list: { Layout: ReturnType<typeof listLayoutFor>; props: ListLayoutProps } | null = null
358
+ if (resolved.kind === 'index' || resolved.kind === 'term') {
359
+ const key = resolved.type === 'blog' ? 'post' : resolved.type.key
360
+ const base = basePath(resolved.base)
361
+ const whole = resolved.kind === 'index' && resolved.cursor === null ? resolved : await resolveRoute(client, base, visitorReads)
362
+ const news = resolved.type === 'blog'
363
+ const q = news && resolved.kind === 'index' ? searchQuery(rawQuery) : null
364
+ list = {
365
+ Layout: listLayoutFor(template, key),
366
+ props: {
367
+ template,
368
+ type: resolved.type,
369
+ base: resolved.base,
370
+ entries: q === null ? resolved.entries : await searchNews(client, q),
371
+ pager: q === null ? pagerOf(resolved, pathname) : { newest: null, older: null },
372
+ filter: whole?.kind === 'index' ? filterOf(whole.entries) : null,
373
+ term: resolved.kind === 'term' ? { taxonomy: resolved.taxonomy, term: resolved.term } : null,
374
+ search: news ? { action: base, q } : null,
375
+ intro: resolved.kind === 'index' ? resolved.intro : null,
376
+ areas,
377
+ },
378
+ }
379
+ }
380
+ const ListLayout = list?.Layout ?? null
381
+ const EntryLayout = resolved.kind === 'entry' ? entryLayoutFor(template, resolved.entry.type) : null
382
+ const LessonLayout = resolved.kind === 'lesson' ? lessonLayoutFor(template) : null
383
+ const VolunteerListLayout = volunteerList ? volunteerLayoutFor(template, 'list') : null
384
+ /** What the header's Sign in names to the portal's door: a lesson, or a course's title on the course's page. */
385
+ const signInTitle =
386
+ resolved.kind === 'lesson'
387
+ ? lessonSignInTitle(resolved.lesson)
388
+ : resolved.kind === 'entry' && resolved.type.key === COURSE_TYPE_KEY
389
+ ? resolved.entry.title
390
+ : null
391
+ const avatar = resolved.kind === 'author' ? safeSrc(resolved.author.avatar_url) : null
392
+ const authorLink = resolved.kind === 'author' ? safeHref(resolved.author.link_url) : null
393
+ ---
394
+ <Site {...head} template={template} page={menuPage} areas={areas} signInTitle={signInTitle} cart={store ? checkout : null}>
395
+ {store?.kind === 'store' && <StorePage template={template} siteName={siteName} shop={store.shop} department={store.department} intro={store.intro} pager={storePager} filters={store.filters} />}
396
+ {store?.kind === 'product' && <ProductPage product={store.product} siteName={siteName} />}
397
+ {store?.kind === 'collection' && <CollectionPage collection={store.collection} />}
398
+ {storeMore && <Area name="sidebar" areas={areas} components={sections} class="store-more" />}
399
+ {store && <StoreScript />}
400
+ {!store && resolved.kind === 'author' && (
401
+ <div class="listing">
402
+ <header class="page-header author">
403
+ {avatar && <img class="author-avatar" src={avatar} alt="" />}
404
+ <h1>{resolved.author.display_name}</h1>
405
+ {resolved.author.bio && <p class="lede">{resolved.author.bio}</p>}
406
+ {authorLink && <p><a href={authorLink} rel={relFor(authorLink)}>More about {resolved.author.display_name}</a></p>}
407
+ </header>
408
+ {resolved.entries.length > 0 && (
409
+ <div class="grid grid-3">{resolved.entries.map((entry) => <EntryCard card={entryCard(entry)} />)}</div>
410
+ )}
411
+ </div>
412
+ )}
413
+
414
+ {!store && resolved.kind === 'not_found' && !volunteerList && (event ? <EventLayout event={event.event} /> : <NotFoundLayout />)}
415
+ {VolunteerListLayout && (
416
+ <div class:list={['layout', sidebar && 'layout-split']}>
417
+ <div class="layout-main"><VolunteerListLayout shifts={shifts ?? []} siteName={siteName} /></div>
418
+ {sidebar && <div class="layout-rail"><Area name="sidebar" areas={areas} components={sections} class="rail" /></div>}
419
+ </div>
420
+ )}
421
+ {eventMore && event && <Area name="sidebar" areas={event.areas} components={sections} class="event-more" />}
422
+
423
+ {!store && heroOverSplit && resolved.kind === 'page' && <PageSections template={template} page={resolved.page} siteName={siteName} only="lead" />}
424
+ {!store && resolved.kind !== 'author' && resolved.kind !== 'not_found' && (
425
+ <div class:list={['layout', sidebar && 'layout-split']}>
426
+ <div class="layout-main">
427
+ {resolved.kind === 'page' && <PageSections template={template} page={resolved.page} siteName={siteName} only={heroOverSplit ? 'rest' : undefined} />}
428
+ {resolved.kind === 'entry' && EntryLayout && <EntryLayout entry={resolved.entry} type={resolved.type} areas={areas} />}
429
+ {resolved.kind === 'lesson' && LessonLayout && <LessonLayout entry={resolved.lesson.lesson} type={undefined} areas={areas} lesson={resolved.lesson} />}
430
+ {ListLayout && list && <ListLayout {...list.props} />}
431
+ </div>
432
+ {sidebar && <div class="layout-rail"><Area name="sidebar" areas={areas} components={sections} class="rail" /></div>}
433
+ </div>
434
+ )}
435
+ </Site>