@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,476 @@
1
+ // The events page's type tabs and its `/events/<type>` addresses (board A6),
2
+ // read from the Content API's `GET /events?type=&cursor=&limit=`: upcoming
3
+ // events only, soonest first, each row shaped like an EventsList row, with
4
+ // every event type and how many upcoming events it has. The client has no
5
+ // method for the route yet, so it is read through `client.raw`, which caches
6
+ // it under the content version like every other read. Each answer is read
7
+ // once per request however many sections ask for it.
8
+ //
9
+ // Each event's own page is `/events/<slug>` on this site (board A7), read
10
+ // from `GET /events/<slug>` the same way. An event row's `url` is its page on
11
+ // BackGold; eventPagePath turns it into the address here, so every list,
12
+ // card and agenda row opens the event on the site.
13
+
14
+ import { BackgoldApiError } from '@backgold/content'
15
+ import type { Areas, BackgoldContent, PageResponse, Section, SectionEmbed } from '@backgold/content'
16
+ import { resolveRoute } from '@backgold/astro/server'
17
+
18
+ /** The built-in events page's address, where the tabs lead. */
19
+ export const EVENTS_PATH = '/events'
20
+
21
+ export interface EventType {
22
+ key: string
23
+ label: string
24
+ /** How many upcoming events have this type. */
25
+ upcoming: number
26
+ }
27
+
28
+ export interface EventsListing {
29
+ /** Rows shaped like an EventsList section's `data.items`. */
30
+ events: Record<string, unknown>[]
31
+ types: EventType[]
32
+ next_cursor: string | null
33
+ }
34
+
35
+ const isRecord = (value: unknown): value is Record<string, unknown> => !!value && typeof value === 'object' && !Array.isArray(value)
36
+
37
+ function listingOf(body: unknown): EventsListing | null {
38
+ if (!isRecord(body) || !Array.isArray(body.events) || !Array.isArray(body.types)) return null
39
+ const types = body.types.flatMap((t): EventType[] =>
40
+ isRecord(t) && typeof t.key === 'string' && t.key !== '' && typeof t.label === 'string' && t.label.trim() !== '' && typeof t.upcoming === 'number'
41
+ ? [{ key: t.key, label: t.label, upcoming: t.upcoming }]
42
+ : [],
43
+ )
44
+ return { events: body.events.filter(isRecord), types, next_cursor: typeof body.next_cursor === 'string' ? body.next_cursor : null }
45
+ }
46
+
47
+ const read = new WeakMap<Request, Map<string, Promise<EventsListing | null>>>()
48
+
49
+ /**
50
+ * `GET /events` with `type` and `limit` when given; null when the answer is
51
+ * not the route's shape. A failed read throws (BackgoldApiError).
52
+ */
53
+ export function eventsListing(client: BackgoldContent, request: Request, query: { type?: string; limit?: number }): Promise<EventsListing | null> {
54
+ const params = { type: query.type, limit: query.limit === undefined ? undefined : String(query.limit) }
55
+ const key = `${params.type ?? ''}\n${params.limit ?? ''}`
56
+ let seen = read.get(request)
57
+ if (!seen) read.set(request, (seen = new Map()))
58
+ let answer = seen.get(key)
59
+ if (!answer) {
60
+ answer = client.raw<unknown>('/events', params).then(listingOf)
61
+ seen.set(key, answer)
62
+ }
63
+ return answer
64
+ }
65
+
66
+ /** The tabs after "All": every type with an upcoming event, in the api's order. */
67
+ export function typeTabs(listing: EventsListing | null): EventType[] {
68
+ return (listing?.types ?? []).filter((t) => t.upcoming > 0)
69
+ }
70
+
71
+ /** The type key `/events/<key>` names, or null for any other path. */
72
+ export function eventTypeKeyOf(pathname: string): string | null {
73
+ const m = /^\/events\/([^/]+)\/?$/.exec(pathname)
74
+ if (!m) return null
75
+ try {
76
+ return decodeURIComponent(m[1]!)
77
+ } catch {
78
+ return null
79
+ }
80
+ }
81
+
82
+ /** A type's address under the events page. */
83
+ export const eventTypePath = (key: string): string => `${EVENTS_PATH}/${encodeURIComponent(key)}`
84
+
85
+ /** An EventsList in its Calendar layout: a month at a time, read by its own window. */
86
+ export const drawsCalendar = (section: Section): boolean => section.type === 'EventsList' && section.variant === 'calendar'
87
+
88
+ /** The sections whose layout draws the tabs: an EventsList in its Agenda or Calendar layout. */
89
+ export const drawsTabs = (section: Section): boolean =>
90
+ section.type === 'EventsList' && (section.variant === 'agenda' || section.variant === 'calendar')
91
+
92
+ /**
93
+ * The most rows `GET /events` returns in one read: the route answers 400
94
+ * BAD_LIMIT for a `limit` outside 1 to 50 (the api's ENTRY_LIMIT_MAX, which
95
+ * no package the template reads exports).
96
+ */
97
+ const EVENTS_LIMIT_MAX = 50
98
+
99
+ /** The section's row cap as a `limit`, at most EVENTS_LIMIT_MAX. */
100
+ function capOf(section: Section): number | undefined {
101
+ const max = section.options?.max
102
+ return typeof max === 'number' && Number.isFinite(max) && max > 0 ? Math.min(Math.floor(max), EVENTS_LIMIT_MAX) : undefined
103
+ }
104
+
105
+ /**
106
+ * The tabs an Agenda or Calendar section draws on the events page (`/events` or
107
+ * `/events/<key>`) and the key of the one being shown (null for All); null
108
+ * anywhere else, when fewer than two types have an upcoming event (an "All"
109
+ * beside the one type would filter nothing), or when the route cannot be read
110
+ * (the section then draws without tabs). On `/events/<key>` it reuses
111
+ * the read that filtered the rows; on `/events` it asks for one row, since
112
+ * only the types are wanted.
113
+ */
114
+ export async function tabsFor(
115
+ client: BackgoldContent,
116
+ request: Request,
117
+ section: Section,
118
+ pathname: string,
119
+ ): Promise<{ tabs: EventType[]; active: string | null } | null> {
120
+ const active = eventTypeKeyOf(pathname)
121
+ if (active === null && pathname.replace(/\/+$/, '') !== EVENTS_PATH) return null
122
+ let listing: EventsListing | null
123
+ try {
124
+ listing = await eventsListing(client, request, active === null ? { limit: 1 } : { type: active, limit: capOf(section) })
125
+ } catch {
126
+ return null
127
+ }
128
+ const tabs = typeTabs(listing)
129
+ return tabs.length > 1 ? { tabs, active } : null
130
+ }
131
+
132
+ /** Whether the path is the events page, `/events` or a type's `/events/<key>`. */
133
+ export const onEventsPage = (pathname: string): boolean => pathname.replace(/\/+$/, '') === EVENTS_PATH || eventTypeKeyOf(pathname) !== null
134
+
135
+ /**
136
+ * `/events/<key>`: the events page with each Agenda and Calendar section's rows read from
137
+ * `GET /events?type=<key>`, and the type. Null (a 404) when the path names no
138
+ * type, the events page has no Agenda or Calendar section, or the key is not a type with
139
+ * an upcoming event (one the tabs do not offer), including a key the api
140
+ * refuses as no type at all. Other sections keep their baked rows; any other
141
+ * failed read throws.
142
+ */
143
+ export async function typedEventsPage(
144
+ client: BackgoldContent,
145
+ request: Request,
146
+ pathname: string,
147
+ ): Promise<{ page: PageResponse; type: EventType } | null> {
148
+ const key = eventTypeKeyOf(pathname)
149
+ if (key === null) return null
150
+ const events = await resolveRoute(client, EVENTS_PATH)
151
+ if (events.kind !== 'page') return null
152
+ const agenda = events.page.sections.filter(drawsTabs)
153
+ if (agenda.length === 0) return null
154
+ let listing: EventsListing | null
155
+ try {
156
+ listing = await eventsListing(client, request, { type: key, limit: capOf(agenda[0]!) })
157
+ } catch (error) {
158
+ // An api without the route answers 404: no type has an address yet. A key
159
+ // outside the api's event types answers 400 BAD_TYPE: no such type. Any
160
+ // other 400 (BAD_LIMIT, BAD_CURSOR) is the template's own mistake and throws.
161
+ if (error instanceof BackgoldApiError && (error.status === 404 || (error.status === 400 && error.code === 'BAD_TYPE'))) return null
162
+ throw error
163
+ }
164
+ const type = typeTabs(listing).find((t) => t.key === key)
165
+ if (!listing || !type) return null
166
+ const rows = listing.events
167
+ const sections = events.page.sections.map((s) => (drawsTabs(s) ? { ...s, data: { source: s.data?.source ?? 'events', items: rows } } : s))
168
+ return { page: { ...events.page, sections }, type }
169
+ }
170
+
171
+ // ── The calendar's month ────────────────────────────────────────────────────
172
+ //
173
+ // A calendar shows one month: `?month=YYYY-MM` on its page's address, else
174
+ // the month it is today. Its rows come from `GET /events?from=&to=`, a window
175
+ // of days (past ones included) the api takes up to 42 of. The api's days are
176
+ // UTC days and each event is placed on its day in its own time zone, so the
177
+ // window runs a day either side of the month and the calendar keeps the rows
178
+ // that fall in the month.
179
+
180
+ /** The query parameter that names the calendar's month. */
181
+ export const MONTH_PARAM = 'month'
182
+
183
+ export interface CalendarMonth {
184
+ year: number
185
+ /** 0 for January. */
186
+ monthIndex: number
187
+ }
188
+
189
+ /** How far from the current month the calendar's arrows go: a year back, two ahead. */
190
+ const MONTHS_BACK = 12
191
+ const MONTHS_AHEAD = 24
192
+
193
+ const monthKey = (m: CalendarMonth) => m.year * 12 + m.monthIndex
194
+ const monthOfKey = (key: number): CalendarMonth => ({ year: Math.floor(key / 12), monthIndex: key % 12 })
195
+
196
+ /** `month` moved by `by` months. */
197
+ export const shiftMonth = (month: CalendarMonth, by: number): CalendarMonth => monthOfKey(monthKey(month) + by)
198
+
199
+ /** Whether `month` is one the calendar's arrows reach from `current`. */
200
+ export function monthInReach(month: CalendarMonth, current: CalendarMonth): boolean {
201
+ const offset = monthKey(month) - monthKey(current)
202
+ return offset >= -MONTHS_BACK && offset <= MONTHS_AHEAD
203
+ }
204
+
205
+ /** `?month=YYYY-MM` as a month inside reach of `current`, else null (the calendar shows `current`). */
206
+ export function monthOf(value: string | null, current: CalendarMonth): CalendarMonth | null {
207
+ const m = value ? /^(\d{4})-(0[1-9]|1[0-2])$/.exec(value) : null
208
+ if (!m) return null
209
+ const month = { year: Number(m[1]), monthIndex: Number(m[2]) - 1 }
210
+ return monthInReach(month, current) ? month : null
211
+ }
212
+
213
+ /** "2026-10": the month as `?month=` names it. */
214
+ export const monthParam = (m: CalendarMonth): string => `${m.year}-${String(m.monthIndex + 1).padStart(2, '0')}`
215
+
216
+ /** Today's date in `timeZone` (UTC when it is not one Intl knows). */
217
+ export function todayIn(timeZone: string | null): CalendarMonth & { day: number } {
218
+ let parts: Intl.DateTimeFormatPart[]
219
+ try {
220
+ parts = new Intl.DateTimeFormat('en-US', { year: 'numeric', month: 'numeric', day: 'numeric', timeZone: timeZone ?? 'UTC' }).formatToParts(new Date())
221
+ } catch {
222
+ parts = new Intl.DateTimeFormat('en-US', { year: 'numeric', month: 'numeric', day: 'numeric', timeZone: 'UTC' }).formatToParts(new Date())
223
+ }
224
+ const part = (type: string) => Number(parts.find((p) => p.type === type)?.value)
225
+ return { year: part('year'), monthIndex: part('month') - 1, day: part('day') }
226
+ }
227
+
228
+ const isoDay = (ms: number) => new Date(ms).toISOString().slice(0, 10)
229
+
230
+ /** How many pages of 50 a month reads at most: 200 events. */
231
+ const MONTH_PAGES_MAX = 4
232
+
233
+ const monthReads = new WeakMap<Request, Map<string, Promise<Record<string, unknown>[] | null>>>()
234
+
235
+ /**
236
+ * The month's events with a day either side, soonest first, from `GET
237
+ * /events?from=&to=` (narrowed to `type` when given), up to 200 of them; null
238
+ * when the answer is not the route's shape. A failed read throws
239
+ * (BackgoldApiError). Read once per request however many sections ask.
240
+ */
241
+ export function monthEvents(
242
+ client: BackgoldContent,
243
+ request: Request,
244
+ month: CalendarMonth,
245
+ type: string | null,
246
+ ): Promise<Record<string, unknown>[] | null> {
247
+ const from = isoDay(Date.UTC(month.year, month.monthIndex, 0))
248
+ const to = isoDay(Date.UTC(month.year, month.monthIndex + 1, 1))
249
+ const key = `${from}\n${to}\n${type ?? ''}`
250
+ let seen = monthReads.get(request)
251
+ if (!seen) monthReads.set(request, (seen = new Map()))
252
+ let answer = seen.get(key)
253
+ if (!answer) {
254
+ answer = (async () => {
255
+ const rows: Record<string, unknown>[] = []
256
+ let cursor: string | undefined
257
+ for (let page = 0; page < MONTH_PAGES_MAX; page++) {
258
+ const listing = listingOf(
259
+ await client.raw<unknown>('/events', { from, to, type: type ?? undefined, limit: String(EVENTS_LIMIT_MAX), cursor }),
260
+ )
261
+ if (!listing) return null
262
+ rows.push(...listing.events)
263
+ if (!listing.next_cursor) break
264
+ cursor = listing.next_cursor
265
+ }
266
+ return rows
267
+ })()
268
+ seen.set(key, answer)
269
+ }
270
+ return answer
271
+ }
272
+
273
+ /**
274
+ * The event's page on this site for a row's `url` (its page on BackGold, whose
275
+ * last path part is the event's slug): `/events/<slug>`. Null when the value
276
+ * is not an address with a path.
277
+ */
278
+ export function eventPagePath(url: unknown): string | null {
279
+ if (typeof url !== 'string' || url.trim() === '') return null
280
+ let path: string
281
+ try {
282
+ path = new URL(url, 'https://site.invalid').pathname
283
+ } catch {
284
+ return null
285
+ }
286
+ const slug = path.split('/').filter(Boolean).at(-1)
287
+ return slug ? `${EVENTS_PATH}/${slug}` : null
288
+ }
289
+
290
+ /** One event as `GET /events/<slug>` answers it: its list row and what its page shows. */
291
+ export interface EventDetail {
292
+ id: string
293
+ slug: string
294
+ title: string
295
+ starts_at: string
296
+ ends_at: string | null
297
+ timezone: string | null
298
+ /** The type key (`fundraiser`), or null. */
299
+ type: string | null
300
+ location: string | null
301
+ is_virtual: boolean
302
+ sells_tickets: boolean
303
+ description: string | null
304
+ venue: string | null
305
+ address: string | null
306
+ image_url: string | null
307
+ /** The venue's coordinates, for the map; null without them. */
308
+ lat: number | null
309
+ lng: number | null
310
+ /** A maps link out to the venue; null for an online event or one with no place. */
311
+ directions_url: string | null
312
+ embed: SectionEmbed
313
+ }
314
+
315
+ function detailOf(body: unknown): { event: EventDetail; areas: Areas } | null {
316
+ if (!isRecord(body) || !isRecord(body.event) || !isRecord(body.areas)) return null
317
+ const e = body.event
318
+ const embed = e.embed
319
+ if (typeof e.id !== 'string' || typeof e.slug !== 'string' || typeof e.title !== 'string' || typeof e.starts_at !== 'string') return null
320
+ if (!isRecord(embed) || typeof embed.script !== 'string' || !(typeof embed.iframe === 'string' || embed.iframe === null)) return null
321
+ const str = (v: unknown) => (typeof v === 'string' && v.trim() !== '' ? v : null)
322
+ const num = (v: unknown) => (typeof v === 'number' && Number.isFinite(v) ? v : null)
323
+ return {
324
+ event: {
325
+ id: e.id,
326
+ slug: e.slug,
327
+ title: e.title,
328
+ starts_at: e.starts_at,
329
+ ends_at: str(e.ends_at),
330
+ timezone: str(e.timezone),
331
+ type: str(e.type),
332
+ location: str(e.location),
333
+ is_virtual: e.is_virtual === true,
334
+ sells_tickets: e.sells_tickets === true,
335
+ description: str(e.description),
336
+ venue: str(e.venue),
337
+ address: str(e.address),
338
+ image_url: str(e.image_url),
339
+ lat: num(e.lat),
340
+ lng: num(e.lng),
341
+ directions_url: str(e.directions_url),
342
+ embed: { iframe: embed.iframe as string | null, script: embed.script },
343
+ },
344
+ areas: body.areas as Areas,
345
+ }
346
+ }
347
+
348
+ /** The slug `/events/<slug>` names, or null for any other path. */
349
+ export const eventSlugOf = eventTypeKeyOf
350
+
351
+ /**
352
+ * `/events/<slug>`: the event and its page's areas, or null (a 404) when the
353
+ * path names none, the api has no such event, or the answer is not the
354
+ * route's shape. Any other failed read throws.
355
+ */
356
+ export async function eventPage(client: BackgoldContent, pathname: string): Promise<{ event: EventDetail; areas: Areas } | null> {
357
+ const slug = eventSlugOf(pathname)
358
+ if (slug === null) return null
359
+ let body: unknown
360
+ try {
361
+ body = await client.raw<unknown>(`${EVENTS_PATH}/${encodeURIComponent(slug)}`)
362
+ } catch (error) {
363
+ if (error instanceof BackgoldApiError && error.status === 404) return null
364
+ throw error
365
+ }
366
+ return detailOf(body)
367
+ }
368
+
369
+ /** The address of an event's calendar file on this site: `/events/<slug>.ics`. */
370
+ export const eventCalendarPath = (slug: string): string => `${EVENTS_PATH}/${encodeURIComponent(slug)}.ics`
371
+
372
+ /** The address of every upcoming event as one calendar file: `/events.ics` (the events page's "Add every event to your calendar"). */
373
+ export const EVENTS_CALENDAR_PATH = `${EVENTS_PATH}.ics`
374
+
375
+ /** The slug `/events/<slug>.ics` names, or null for any other path. */
376
+ export function calendarSlugOf(pathname: string): string | null {
377
+ const m = /^\/events\/([^/]+)\.ics$/.exec(pathname)
378
+ if (!m) return null
379
+ try {
380
+ return decodeURIComponent(m[1]!)
381
+ } catch {
382
+ return null
383
+ }
384
+ }
385
+
386
+ /** Text as an iCalendar value: backslash, comma, semicolon and line breaks escaped. */
387
+ const icsText = (value: string): string => value.replace(/\\/g, '\\\\').replace(/([,;])/g, '\\$1').replace(/\r?\n/g, '\\n')
388
+
389
+ /** An instant as iCalendar UTC, `20261101T013000Z`; null when it does not parse. */
390
+ function icsInstant(value: string | null): string | null {
391
+ if (!value) return null
392
+ const date = new Date(value)
393
+ return Number.isNaN(date.getTime()) ? null : date.toISOString().replace(/[-:]/g, '').replace(/\.\d{3}Z$/, 'Z')
394
+ }
395
+
396
+ /** What a calendar entry needs of an event: its page's fields, or a list row's (which has no venue or address). */
397
+ type CalendarEvent = Pick<EventDetail, 'id' | 'title' | 'starts_at' | 'ends_at' | 'location'> & Partial<Pick<EventDetail, 'venue' | 'address'>>
398
+
399
+ /**
400
+ * One event's VEVENT lines: its title, start and end (an hour when it has no
401
+ * end), place and its page on this site. Null when the start does not parse.
402
+ */
403
+ function vevent(event: CalendarEvent, pageUrl: string, host: string): string[] | null {
404
+ const start = icsInstant(event.starts_at)
405
+ if (!start) return null
406
+ const end = icsInstant(event.ends_at) ?? icsInstant(new Date(new Date(event.starts_at).getTime() + 3_600_000).toISOString())
407
+ const place = [event.venue ?? event.location, event.venue ? event.address : null].filter(Boolean).join(', ')
408
+ return [
409
+ 'BEGIN:VEVENT',
410
+ `UID:${icsText(event.id)}@${icsText(host)}`,
411
+ `DTSTAMP:${start}`,
412
+ `DTSTART:${start}`,
413
+ `DTEND:${end}`,
414
+ `SUMMARY:${icsText(event.title)}`,
415
+ ...(place ? [`LOCATION:${icsText(place)}`] : []),
416
+ `URL:${pageUrl}`,
417
+ 'END:VEVENT',
418
+ ]
419
+ }
420
+
421
+ /** VEVENTs wrapped as an iCalendar file, named `name` in a calendar app when given. */
422
+ function calendarFile(events: string[][], name?: string): string {
423
+ const lines = [
424
+ 'BEGIN:VCALENDAR',
425
+ 'VERSION:2.0',
426
+ 'PRODID:-//BackGold//Party template//EN',
427
+ ...(name ? [`X-WR-CALNAME:${icsText(name)}`] : []),
428
+ ...events.flat(),
429
+ 'END:VCALENDAR',
430
+ ]
431
+ return `${lines.join('\r\n')}\r\n`
432
+ }
433
+
434
+ /**
435
+ * The event as a one-event iCalendar file (Add to calendar). Null when the
436
+ * start does not parse.
437
+ */
438
+ export function eventCalendar(event: EventDetail, pageUrl: string, host: string): string | null {
439
+ const entry = vevent(event, pageUrl, host)
440
+ return entry ? calendarFile([entry]) : null
441
+ }
442
+
443
+ /** How many pages of 50 the all-events file reads at most: 200 events. */
444
+ const CALENDAR_PAGES_MAX = 4
445
+
446
+ /**
447
+ * Every upcoming event as one iCalendar file (`/events.ics`), from `GET
448
+ * /events` (the read the events page's rows come from), soonest first, up to
449
+ * 200 of them, each entry the one its own page's file carries, linking to
450
+ * its page on this site; a row with no page or no start that parses is left
451
+ * out. Null when the answer is not the route's shape. A failed read throws
452
+ * (BackgoldApiError).
453
+ */
454
+ export async function eventsCalendar(client: BackgoldContent, siteUrl: string, name: string): Promise<string | null> {
455
+ const host = new URL(siteUrl).host
456
+ const str = (v: unknown) => (typeof v === 'string' && v.trim() !== '' ? v : null)
457
+ const entries: string[][] = []
458
+ let cursor: string | undefined
459
+ for (let page = 0; page < CALENDAR_PAGES_MAX; page++) {
460
+ const listing = listingOf(await client.raw<unknown>(EVENTS_PATH, { limit: String(EVENTS_LIMIT_MAX), cursor }))
461
+ if (!listing) return null
462
+ for (const row of listing.events) {
463
+ const path = eventPagePath(row.url)
464
+ if (!path || typeof row.id !== 'string' || typeof row.title !== 'string' || typeof row.starts_at !== 'string') continue
465
+ const entry = vevent(
466
+ { id: row.id, title: row.title, starts_at: row.starts_at, ends_at: str(row.ends_at), location: str(row.location) },
467
+ new URL(path, siteUrl).toString(),
468
+ host,
469
+ )
470
+ if (entry) entries.push(entry)
471
+ }
472
+ if (!listing.next_cursor) break
473
+ cursor = listing.next_cursor
474
+ }
475
+ return calendarFile(entries, name)
476
+ }
@@ -0,0 +1,116 @@
1
+ // The site's faces, as the layout (src/layouts/Site.astro) loads them.
2
+ //
3
+ // A site wearing a saved theme in BackGold names two faces in `/site`'s
4
+ // `theme.fonts`, `heading` and `body`: each a family, its CSS stack, and
5
+ // where it comes from. `builtin` (one of BackGold's faces) and `fontsource`
6
+ // (a family the organization imported) are woff2 files BackGold serves at
7
+ // `/lp-runtime/<hash>.woff2`, one per weight, listed in the face's `files`;
8
+ // `system` downloads nothing. They are declared the way a hosted BackGold
9
+ // page declares them: one @font-face rule per weight, `font-display: swap`,
10
+ // never render-blocking. The stacks become `--site-font-heading` and
11
+ // `--site-font-body`, which src/styles/site.css's `--font-display` and
12
+ // `--font` read.
13
+ //
14
+ // Where the files load from follows how the site reads BackGold, as the live
15
+ // counts do (src/lib/live.ts). First-party (inside BackGold's namespace) the
16
+ // api serves /lp-runtime on the site's own host, so the rules name the
17
+ // same-origin path, exactly as a hosted page does, and nothing is
18
+ // preconnected. With a site key they name the api's address the theme gives,
19
+ // and the page preconnects to it.
20
+ //
21
+ // A slot with no theme face, or one whose family, stack or source is not of
22
+ // the shapes above, keeps the template's own face for it, from Google Fonts:
23
+ // the `fonts` of the template's config (src/template.ts). A file whose weight or address is
24
+ // not of those shapes is left out, as a hosted page leaves out a weight it has
25
+ // no file for. Every value written into CSS passed one of the patterns below,
26
+ // so none carries anything but a family name, a stack or a file address.
27
+
28
+ import type { SiteResponse } from '@backgold/content'
29
+ import type { TemplateConfig } from '../template'
30
+
31
+ type SiteTheme = SiteResponse['site']['theme']
32
+
33
+ const GOOGLE_FONTS = 'https://fonts.googleapis.com'
34
+ const GOOGLE_FILES = 'https://fonts.gstatic.com'
35
+
36
+ /** A family as BackGold names one (letters, digits, spaces, `+`, `-`). */
37
+ const FAMILY = /^[A-Za-z0-9][A-Za-z0-9 +-]{0,63}$/
38
+ /** A stack: quoted family names and bare keywords (`serif`, `-apple-system`), comma-separated. */
39
+ const STACK = /^(?:"[A-Za-z0-9 +-]{1,64}"|'[A-Za-z0-9 +-]{1,64}'|-?[A-Za-z][A-Za-z0-9-]{0,63})(?:\s*,\s*(?:"[A-Za-z0-9 +-]{1,64}"|'[A-Za-z0-9 +-]{1,64}'|-?[A-Za-z][A-Za-z0-9-]{0,63}))*$/
40
+ /** A woff2 file as BackGold serves one: content-addressed under /lp-runtime. */
41
+ const FILE_PATH = /^\/lp-runtime\/[0-9a-f]{64}\.woff2$/
42
+
43
+ type Slot = 'heading' | 'body'
44
+
45
+ interface Face {
46
+ family: string
47
+ stack: string
48
+ /** Each weight's file address, as the page names it. */
49
+ files: Array<{ weight: number; href: string; origin: string }>
50
+ }
51
+
52
+ export interface SiteFonts {
53
+ /** The theme's stacks as custom properties and its @font-face rules; '' when the template's own faces are all there is. */
54
+ css: string
55
+ /** The Google Fonts stylesheet for the template's own faces still in use; null when the theme replaced both. */
56
+ stylesheet: string | null
57
+ /** The origins the page connects to for its faces; `crossorigin` for the ones serving font files. */
58
+ preconnects: Array<{ href: string; crossorigin: boolean }>
59
+ }
60
+
61
+ function record(value: unknown): Record<string, unknown> | null {
62
+ return value && typeof value === 'object' ? (value as Record<string, unknown>) : null
63
+ }
64
+
65
+ /** A file of a face: its weight and its address on the page, or null when either is not one BackGold serves. */
66
+ function fileOf(value: unknown, firstParty: boolean): Face['files'][number] | null {
67
+ const file = record(value)
68
+ const weight = file?.weight
69
+ if (typeof weight !== 'number' || !Number.isInteger(weight) || weight < 100 || weight > 900 || typeof file?.url !== 'string') return null
70
+ let url: URL
71
+ try {
72
+ url = new URL(file.url)
73
+ } catch {
74
+ return null
75
+ }
76
+ if ((url.protocol !== 'https:' && url.protocol !== 'http:') || url.search || url.hash || !FILE_PATH.test(url.pathname)) return null
77
+ return firstParty ? { weight, href: url.pathname, origin: '' } : { weight, href: `${url.origin}${url.pathname}`, origin: url.origin }
78
+ }
79
+
80
+ /** A theme face the page can declare, or null when it is missing or not of the shapes above. */
81
+ function faceOf(value: unknown, firstParty: boolean): Face | null {
82
+ const face = record(value)
83
+ if (!face || typeof face.family !== 'string' || typeof face.stack !== 'string') return null
84
+ if (!FAMILY.test(face.family) || face.stack.length > 400 || !STACK.test(face.stack)) return null
85
+ if (face.source === 'system') return { family: face.family, stack: face.stack, files: [] }
86
+ if (face.source !== 'builtin' && face.source !== 'fontsource') return null
87
+ const files = (Array.isArray(face.files) ? face.files : []).flatMap((f) => fileOf(f, firstParty) ?? [])
88
+ return { family: face.family, stack: face.stack, files }
89
+ }
90
+
91
+ /** The faces a page of this site loads, and how (see the top of this file). */
92
+ export function siteFonts(theme: SiteTheme | undefined, firstParty: boolean, ownFaces: TemplateConfig['fonts']): SiteFonts {
93
+ const fonts = record(record(theme)?.fonts)
94
+ const faces: Record<Slot, Face | null> = { heading: faceOf(fonts?.heading, firstParty), body: faceOf(fonts?.body, firstParty) }
95
+ const props: string[] = []
96
+ const rules: string[] = []
97
+ const origins = new Set<string>()
98
+ for (const slot of ['heading', 'body'] as const) {
99
+ const face = faces[slot]
100
+ if (!face) continue
101
+ props.push(`--site-font-${slot}:${face.stack}`)
102
+ for (const file of face.files) {
103
+ const rule = `@font-face{font-family:"${face.family}";font-style:normal;font-weight:${file.weight};font-display:swap;src:url(${file.href}) format('woff2')}`
104
+ if (!rules.includes(rule)) rules.push(rule)
105
+ if (file.origin) origins.add(file.origin)
106
+ }
107
+ }
108
+ const own = (['heading', 'body'] as const).filter((slot) => !faces[slot]).map((slot) => ownFaces[slot])
109
+ const preconnects = [...origins].map((href) => ({ href, crossorigin: true }))
110
+ if (own.length > 0) preconnects.unshift({ href: GOOGLE_FONTS, crossorigin: false }, { href: GOOGLE_FILES, crossorigin: true })
111
+ return {
112
+ css: props.length > 0 ? `:root{${props.join(';')}}${rules.join('')}` : '',
113
+ stylesheet: own.length > 0 ? `${GOOGLE_FONTS}/css2?${own.map((family) => `family=${family}`).join('&')}&display=swap` : null,
114
+ preconnects,
115
+ }
116
+ }
@@ -0,0 +1,24 @@
1
+ // The footer menu as columns, from `menuOf` (the Shows on rules already
2
+ // applied). Each group is a column headed by its label, its links under it (a
3
+ // group with an address of its own lists it first; a link nested deeper is
4
+ // listed after its parent, in order). Links that sit at the top level,
5
+ // outside any group, share one column with no heading, before the groups.
6
+ // Site.astro counts the columns to size the footer's grid; FooterColumns
7
+ // draws them.
8
+ import type { MenuNode } from '@backgold/astro/server'
9
+
10
+ export interface FooterColumn {
11
+ label: string | null
12
+ links: MenuNode[]
13
+ }
14
+
15
+ /** A node and every link under it, in menu order, as one flat list. */
16
+ const flat = (node: MenuNode): MenuNode[] => [...(node.href ? [{ ...node, children: [] }] : []), ...node.children.flatMap(flat)]
17
+
18
+ export function footerColumnsOf(nodes: MenuNode[]): FooterColumn[] {
19
+ const loose = nodes.filter((node) => node.children.length === 0)
20
+ return [
21
+ ...(loose.length > 0 ? [{ label: null, links: loose }] : []),
22
+ ...nodes.filter((node) => node.children.length > 0).map((node) => ({ label: node.label, links: flat(node) })),
23
+ ]
24
+ }