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