@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.
- package/LICENSE +21 -0
- package/README.md +12 -2
- package/dist/chunk-RJAVFRC6.js +67 -0
- package/dist/constants-BAIo_Q5U.d-lQbj1e1-.d.ts +48 -0
- package/dist/content-api-Cox1-wz5.d.ts +1096 -0
- package/dist/contract/content-api-examples.d.ts +72 -0
- package/dist/contract/content-api-examples.js +926 -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 +253 -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 +61 -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 +80 -0
- package/src/components/sections/About/index.astro +60 -0
- package/src/components/sections/About/left.astro +57 -0
- package/src/components/sections/About/letter.astro +111 -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 +126 -0
- package/src/components/sections/ContentPost/player.astro +254 -0
- package/src/components/sections/ContentPost/prose.astro +80 -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 +176 -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 +99 -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/Lookup.astro +43 -0
- package/src/components/sections/VoterTools/dates.astro +153 -0
- package/src/components/sections/VoterTools/index.astro +231 -0
- package/src/components/sections/VoterTools/polling.astro +144 -0
- package/src/components/sections/VoterTools/voter-tools.ts +71 -0
- package/src/components/sections/index.ts +373 -0
- package/src/components/sections/modules/Headed.astro +39 -0
- package/src/components/sections/modules/ModuleFrame.astro +181 -0
- package/src/components/store/CollectionPage.astro +40 -0
- package/src/components/store/ProductCard.astro +32 -0
- package/src/components/store/ProductGrid.astro +16 -0
- package/src/components/store/ProductPage.astro +146 -0
- package/src/components/store/StorePage.astro +137 -0
- package/src/components/store/StoreScript.astro +572 -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 +63 -0
- package/src/layouts/Site.astro +387 -0
- package/src/lib/academy.ts +146 -0
- package/src/lib/brand.ts +534 -0
- package/src/lib/chrome.ts +121 -0
- package/src/lib/donate-frame.ts +104 -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 +55 -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 +105 -0
- package/src/lib/shifts.ts +187 -0
- package/src/lib/store.ts +521 -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 +435 -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/styles/entries.css +784 -0
- package/src/styles/site.css +1910 -0
- package/src/styles/store.css +634 -0
- package/src/template.ts +182 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
---
|
|
2
|
+
// Countdown: the eyebrow over the heading, the body line under it with the
|
|
3
|
+
// section's link after it (C1's "Find where to vote"), and the time left
|
|
4
|
+
// until the deadline; each part drawn only when the section has it. Pages are
|
|
5
|
+
// cached until content changes, so the server writes the deadline itself and
|
|
6
|
+
// a few lines of script count the days in the visitor's browser; without
|
|
7
|
+
// script the deadline still reads plainly.
|
|
8
|
+
import type { Section } from '@backgold/content'
|
|
9
|
+
import Band from '../Band.astro'
|
|
10
|
+
import { links, rows } from '../../../lib/section'
|
|
11
|
+
import { formatWhen, text } from '../../../lib/format'
|
|
12
|
+
|
|
13
|
+
interface Props {
|
|
14
|
+
section: Section
|
|
15
|
+
variant?: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const { section } = Astro.props
|
|
19
|
+
const eyebrow = text(section.copy.eyebrow)
|
|
20
|
+
const heading = text(section.copy.heading)
|
|
21
|
+
const body = text(section.copy.body)
|
|
22
|
+
const [link] = links(section)
|
|
23
|
+
const deadline = text(rows(section)[0]?.deadline)
|
|
24
|
+
const when = formatWhen(deadline)
|
|
25
|
+
---
|
|
26
|
+
{deadline && when && (
|
|
27
|
+
<Band section={section} class="countdown">
|
|
28
|
+
{eyebrow && <p class="kicker">{eyebrow}</p>}
|
|
29
|
+
{heading && <h2>{heading}</h2>}
|
|
30
|
+
{(body || link) && (
|
|
31
|
+
<p class="countdown-body">
|
|
32
|
+
{body}{body && link && ' '}{link && <a class="text-link" href={link.href} rel={link.rel}>{link.label}</a>}
|
|
33
|
+
</p>
|
|
34
|
+
)}
|
|
35
|
+
<p class="countdown-left" data-countdown={deadline}>Until <time datetime={deadline}>{when}</time></p>
|
|
36
|
+
<script is:inline>
|
|
37
|
+
(function (el) {
|
|
38
|
+
var end = Date.parse(el.getAttribute('data-countdown'))
|
|
39
|
+
if (isNaN(end)) return
|
|
40
|
+
var ms = end - Date.now()
|
|
41
|
+
if (ms <= 0) return
|
|
42
|
+
var days = Math.floor(ms / 86400000)
|
|
43
|
+
var hours = Math.floor((ms % 86400000) / 3600000)
|
|
44
|
+
var left = days > 0 ? days + (days === 1 ? ' day' : ' days') : hours + (hours === 1 ? ' hour' : ' hours')
|
|
45
|
+
var strong = document.createElement('strong')
|
|
46
|
+
strong.className = 'countdown-number'
|
|
47
|
+
strong.textContent = left
|
|
48
|
+
el.firstChild.textContent = ' left, until '
|
|
49
|
+
el.prepend(strong)
|
|
50
|
+
})(document.currentScript.previousElementSibling)
|
|
51
|
+
</script>
|
|
52
|
+
</Band>
|
|
53
|
+
)}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
---
|
|
2
|
+
// A course's bar (boards D1, D2, D3): a real <progress> at the visitor's
|
|
3
|
+
// lessons finished of the course's lessons, drawn at its value (it never
|
|
4
|
+
// fills up on load). `label` names it for a screen reader ("Foundational
|
|
5
|
+
// Leadership: 4 of 12 lessons"); the words beside it are the layout's.
|
|
6
|
+
interface Props {
|
|
7
|
+
completed: number
|
|
8
|
+
total: number
|
|
9
|
+
label: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const { completed, total, label } = Astro.props
|
|
13
|
+
const max = Math.max(total, 1)
|
|
14
|
+
---
|
|
15
|
+
<progress class="ac-bar" max={max} value={Math.min(completed, max)} aria-label={label}>{completed} of {total}</progress>
|
|
16
|
+
|
|
17
|
+
<style>
|
|
18
|
+
.ac-bar {
|
|
19
|
+
display: block;
|
|
20
|
+
width: 100%;
|
|
21
|
+
height: 0.5rem;
|
|
22
|
+
border: 0;
|
|
23
|
+
border-radius: var(--pill);
|
|
24
|
+
background: color-mix(in srgb, var(--ink) 14%, transparent);
|
|
25
|
+
color: var(--button);
|
|
26
|
+
overflow: hidden;
|
|
27
|
+
appearance: none;
|
|
28
|
+
}
|
|
29
|
+
.ac-bar::-webkit-progress-bar {
|
|
30
|
+
border-radius: var(--pill);
|
|
31
|
+
background: color-mix(in srgb, var(--ink) 14%, transparent);
|
|
32
|
+
}
|
|
33
|
+
.ac-bar::-webkit-progress-value {
|
|
34
|
+
border-radius: var(--pill);
|
|
35
|
+
background: var(--button);
|
|
36
|
+
}
|
|
37
|
+
.ac-bar::-moz-progress-bar {
|
|
38
|
+
border-radius: var(--pill);
|
|
39
|
+
background: var(--button);
|
|
40
|
+
}
|
|
41
|
+
@media (forced-colors: active) {
|
|
42
|
+
.ac-bar {
|
|
43
|
+
border: 1px solid CanvasText;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
</style>
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
---
|
|
2
|
+
// A course's head (board D2): "Course · 12 lessons · 1 h 1 min" as the
|
|
3
|
+
// kicker, the title, the summary, and for a visitor the course's bar with
|
|
4
|
+
// "4 of 12 · 38 min left" and "Lesson 4 finished on Tuesday" (the newest
|
|
5
|
+
// lesson the visitor finished, when the api says when); then the one accent button, "Continue · Lesson 5"
|
|
6
|
+
// with the lesson's title and length under it ("Start · Lesson 1" before the
|
|
7
|
+
// first lesson is finished, nothing once the course is finished, which says
|
|
8
|
+
// Finished instead). Signed out, the line under it says why to sign in. The
|
|
9
|
+
// cover sits at the right (`cover`), above the words on a phone.
|
|
10
|
+
import Bar from './Bar.astro'
|
|
11
|
+
import Icon from './Icon.astro'
|
|
12
|
+
import type { CourseView } from './course'
|
|
13
|
+
import { clockOf, countAndLength, leftOf, stateOf } from '../../../lib/academy'
|
|
14
|
+
|
|
15
|
+
interface Props {
|
|
16
|
+
view: CourseView
|
|
17
|
+
/** The title is the page's <h1> (the course's own page) rather than an <h2>. */
|
|
18
|
+
lead: boolean
|
|
19
|
+
cover: boolean
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const { view, lead, cover } = Astro.props
|
|
23
|
+
const Title = lead ? 'h1' : 'h2'
|
|
24
|
+
const finished = view.progress ? stateOf(view.progress) === 'finished' : false
|
|
25
|
+
const left = view.progress ? leftOf(view.progress) : null
|
|
26
|
+
const nextLength = view.next ? clockOf(view.next.row.seconds) : null
|
|
27
|
+
---
|
|
28
|
+
<header class:list={['cs-head', cover && view.cover && 'cs-head-cover']}>
|
|
29
|
+
{cover && view.cover && <img class="cs-cover" src={view.cover} alt="" decoding="async" />}
|
|
30
|
+
<div class="cs-words">
|
|
31
|
+
<p class="kicker">Course · {countAndLength(view.lessons, view.seconds)}</p>
|
|
32
|
+
<Title class="cs-title">{view.title}</Title>
|
|
33
|
+
{view.summary && <p class="lede cs-summary">{view.summary}</p>}
|
|
34
|
+
{view.progress && (
|
|
35
|
+
<div class="cs-progress">
|
|
36
|
+
<Bar completed={view.progress.completed} total={view.progress.total} label={`${view.title}: ${view.progress.completed} of ${view.progress.total} lessons`} />
|
|
37
|
+
<p class="cs-figures">
|
|
38
|
+
<strong>{view.progress.completed} of {view.progress.total}</strong>
|
|
39
|
+
{left && !finished && <> · {left}</>}
|
|
40
|
+
{finished && <span class="cs-finished"> · <Icon name="check" /> Finished</span>}
|
|
41
|
+
</p>
|
|
42
|
+
{view.lastFinished && <p class="fine cs-last">Lesson {view.lastFinished.n} finished {view.lastFinished.on}</p>}
|
|
43
|
+
</div>
|
|
44
|
+
)}
|
|
45
|
+
{view.next && !finished && (
|
|
46
|
+
<div class="cs-next">
|
|
47
|
+
<a class="button" href={view.next.row.href ?? undefined}>{view.next.verb} · Lesson {view.next.row.n}</a>
|
|
48
|
+
<p class="fine">{nextLength ? `${view.next.row.name} · ${nextLength}` : view.next.row.name}</p>
|
|
49
|
+
</div>
|
|
50
|
+
)}
|
|
51
|
+
{!view.visitor && (
|
|
52
|
+
<p class="fine cs-sign-in">
|
|
53
|
+
Sign in with your email and the Academy keeps your place in every course. <a class="text-link" href={view.signIn}>Sign in</a>
|
|
54
|
+
</p>
|
|
55
|
+
)}
|
|
56
|
+
</div>
|
|
57
|
+
</header>
|
|
58
|
+
|
|
59
|
+
<style>
|
|
60
|
+
.cs-head {
|
|
61
|
+
display: grid;
|
|
62
|
+
gap: 1.5rem;
|
|
63
|
+
margin-bottom: clamp(2rem, 1.5rem + 2vw, 3rem);
|
|
64
|
+
}
|
|
65
|
+
.cs-words {
|
|
66
|
+
display: grid;
|
|
67
|
+
gap: 0.875rem;
|
|
68
|
+
align-content: start;
|
|
69
|
+
min-width: 0;
|
|
70
|
+
}
|
|
71
|
+
.cs-words > * {
|
|
72
|
+
margin: 0;
|
|
73
|
+
}
|
|
74
|
+
.cs-title {
|
|
75
|
+
font-size: var(--h1);
|
|
76
|
+
}
|
|
77
|
+
.cs-cover {
|
|
78
|
+
display: block;
|
|
79
|
+
width: 100%;
|
|
80
|
+
aspect-ratio: 16 / 10;
|
|
81
|
+
border-radius: var(--radius-card);
|
|
82
|
+
object-fit: cover;
|
|
83
|
+
}
|
|
84
|
+
.cs-progress {
|
|
85
|
+
display: grid;
|
|
86
|
+
gap: 0.5rem;
|
|
87
|
+
max-width: 26rem;
|
|
88
|
+
}
|
|
89
|
+
.cs-progress > * {
|
|
90
|
+
margin: 0;
|
|
91
|
+
}
|
|
92
|
+
.cs-figures {
|
|
93
|
+
color: var(--muted);
|
|
94
|
+
font-size: var(--text-sm);
|
|
95
|
+
font-variant-numeric: tabular-nums;
|
|
96
|
+
}
|
|
97
|
+
.cs-figures strong,
|
|
98
|
+
.cs-finished {
|
|
99
|
+
color: var(--ink);
|
|
100
|
+
}
|
|
101
|
+
.cs-next {
|
|
102
|
+
display: grid;
|
|
103
|
+
justify-items: start;
|
|
104
|
+
gap: 0.5rem;
|
|
105
|
+
margin-top: 0.5rem;
|
|
106
|
+
}
|
|
107
|
+
.cs-next > * {
|
|
108
|
+
margin: 0;
|
|
109
|
+
}
|
|
110
|
+
.cs-next .button:focus-visible {
|
|
111
|
+
outline-color: var(--link);
|
|
112
|
+
}
|
|
113
|
+
@media (min-width: 56rem) {
|
|
114
|
+
.cs-head-cover {
|
|
115
|
+
grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
|
|
116
|
+
gap: 3rem;
|
|
117
|
+
align-items: center;
|
|
118
|
+
}
|
|
119
|
+
.cs-head-cover .cs-cover {
|
|
120
|
+
order: 2;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
</style>
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
---
|
|
2
|
+
// The academy's breadcrumb (boards D2, D3): "Courses › Foundational
|
|
3
|
+
// Leadership" on a course, "Courses › Foundational Leadership › Lesson 5" on
|
|
4
|
+
// a lesson, the last step the page itself.
|
|
5
|
+
interface Props {
|
|
6
|
+
steps: { label: string; href: string | null }[]
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const { steps } = Astro.props
|
|
10
|
+
---
|
|
11
|
+
<nav class="ac-crumbs" aria-label="Breadcrumb">
|
|
12
|
+
<ol role="list">
|
|
13
|
+
{steps.map((step, i) => (
|
|
14
|
+
<li>
|
|
15
|
+
{i < steps.length - 1 && step.href ? <a href={step.href}>{step.label}</a> : <span aria-current={i === steps.length - 1 ? 'page' : undefined}>{step.label}</span>}
|
|
16
|
+
</li>
|
|
17
|
+
))}
|
|
18
|
+
</ol>
|
|
19
|
+
</nav>
|
|
20
|
+
|
|
21
|
+
<style>
|
|
22
|
+
.ac-crumbs ol {
|
|
23
|
+
display: flex;
|
|
24
|
+
flex-wrap: wrap;
|
|
25
|
+
gap: 0.25rem 0;
|
|
26
|
+
margin: 0 0 1.25rem;
|
|
27
|
+
padding: 0;
|
|
28
|
+
list-style: none;
|
|
29
|
+
color: var(--muted);
|
|
30
|
+
font-size: var(--text-sm);
|
|
31
|
+
}
|
|
32
|
+
.ac-crumbs li + li::before {
|
|
33
|
+
content: '›';
|
|
34
|
+
padding: 0 0.5rem;
|
|
35
|
+
color: var(--muted);
|
|
36
|
+
}
|
|
37
|
+
.ac-crumbs a {
|
|
38
|
+
color: var(--link);
|
|
39
|
+
font-weight: 600;
|
|
40
|
+
}
|
|
41
|
+
.ac-crumbs [aria-current] {
|
|
42
|
+
color: var(--ink);
|
|
43
|
+
}
|
|
44
|
+
</style>
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
---
|
|
2
|
+
// The academy's two marks: the check beside Done and Finished, the lock
|
|
3
|
+
// beside For members and Sign in to watch. Each only repeats the word
|
|
4
|
+
// printed next to it, so it is hidden from screen readers.
|
|
5
|
+
interface Props {
|
|
6
|
+
name: 'check' | 'lock'
|
|
7
|
+
class?: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const { name, class: className } = Astro.props
|
|
11
|
+
---
|
|
12
|
+
<svg class:list={['ac-icon', className]} viewBox="0 0 20 20" width="16" height="16" aria-hidden="true" focusable="false">
|
|
13
|
+
{name === 'check' && <path d="M4.5 10.5l3.5 3.5 7.5-8" fill="none" stroke="currentColor" stroke-width="2.25" stroke-linecap="round" stroke-linejoin="round" />}
|
|
14
|
+
{name === 'lock' && (
|
|
15
|
+
<>
|
|
16
|
+
<rect x="4" y="9" width="12" height="8.5" rx="2" fill="none" stroke="currentColor" stroke-width="1.8" />
|
|
17
|
+
<path d="M6.75 9V6.75a3.25 3.25 0 0 1 6.5 0V9" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" />
|
|
18
|
+
</>
|
|
19
|
+
)}
|
|
20
|
+
</svg>
|
|
21
|
+
|
|
22
|
+
<style>
|
|
23
|
+
.ac-icon {
|
|
24
|
+
flex: none;
|
|
25
|
+
width: 1em;
|
|
26
|
+
height: 1em;
|
|
27
|
+
vertical-align: -0.125em;
|
|
28
|
+
}
|
|
29
|
+
</style>
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
---
|
|
2
|
+
// A course's ring (board L1's cards, L2's course head, L3's rail): a circle
|
|
3
|
+
// whose arc is `value` of `max`, drawn at its value. The arc has a
|
|
4
|
+
// pathLength of 100, so its dash offset is the share left to go and a
|
|
5
|
+
// template can draw it in from 0 by animating `stroke-dashoffset` from 100
|
|
6
|
+
// on `.ac-ring-arc`. It only repeats the words printed beside it ("4 of 12"),
|
|
7
|
+
// so it is hidden from screen readers. `size` is its width in pixels and
|
|
8
|
+
// `stroke` the line's width as a share of it (out of 40); the track reads
|
|
9
|
+
// --ring-track (else the ink at 16%) and the arc --ring-arc (else the
|
|
10
|
+
// accent). With nothing done, only the track is drawn.
|
|
11
|
+
interface Props {
|
|
12
|
+
value: number
|
|
13
|
+
max: number
|
|
14
|
+
size?: number
|
|
15
|
+
stroke?: number
|
|
16
|
+
class?: string
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const { value, max, size = 56, stroke = 3.5, class: className } = Astro.props
|
|
20
|
+
const share = max > 0 && Number.isFinite(value) ? Math.min(Math.max(value / max, 0), 1) : 0
|
|
21
|
+
const percent = Math.round(share * 1000) / 10
|
|
22
|
+
const r = 20 - stroke / 2
|
|
23
|
+
---
|
|
24
|
+
<svg class:list={['ac-ring', className]} viewBox="0 0 40 40" width={size} height={size} aria-hidden="true" focusable="false">
|
|
25
|
+
<circle class="ac-ring-track" cx="20" cy="20" r={r} fill="none" stroke-width={stroke} />
|
|
26
|
+
{percent > 0 && (
|
|
27
|
+
<circle
|
|
28
|
+
class="ac-ring-arc"
|
|
29
|
+
cx="20"
|
|
30
|
+
cy="20"
|
|
31
|
+
r={r}
|
|
32
|
+
fill="none"
|
|
33
|
+
stroke-width={stroke}
|
|
34
|
+
stroke-linecap={percent < 100 ? 'round' : 'butt'}
|
|
35
|
+
pathLength="100"
|
|
36
|
+
stroke-dasharray="100 100"
|
|
37
|
+
stroke-dashoffset={100 - percent}
|
|
38
|
+
transform="rotate(-90 20 20)"
|
|
39
|
+
/>
|
|
40
|
+
)}
|
|
41
|
+
</svg>
|
|
42
|
+
|
|
43
|
+
<style>
|
|
44
|
+
.ac-ring {
|
|
45
|
+
display: block;
|
|
46
|
+
flex: none;
|
|
47
|
+
}
|
|
48
|
+
.ac-ring-track {
|
|
49
|
+
stroke: var(--ring-track, color-mix(in srgb, var(--ink) 16%, transparent));
|
|
50
|
+
}
|
|
51
|
+
.ac-ring-arc {
|
|
52
|
+
stroke: var(--ring-arc, var(--accent));
|
|
53
|
+
}
|
|
54
|
+
@media (forced-colors: active) {
|
|
55
|
+
.ac-ring-track {
|
|
56
|
+
stroke: GrayText;
|
|
57
|
+
}
|
|
58
|
+
.ac-ring-arc {
|
|
59
|
+
stroke: CanvasText;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
</style>
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
---
|
|
2
|
+
// A course's lessons in order (board D2's syllabus): each row the lesson's
|
|
3
|
+
// mark (its number, the check when this visitor finished it, the lock when
|
|
4
|
+
// they cannot open it), "Lesson 5: Decide what you want" (the whole row is
|
|
5
|
+
// the link to the lesson; a locked one opens its door), the state in words
|
|
6
|
+
// (Done, Up next, For members with Join to watch, Sign in to watch) and the
|
|
7
|
+
// lesson's length at the right.
|
|
8
|
+
import Icon from './Icon.astro'
|
|
9
|
+
import type { SyllabusRow } from './course'
|
|
10
|
+
import { clockOf, lessonTitle } from '../../../lib/academy'
|
|
11
|
+
|
|
12
|
+
interface Props {
|
|
13
|
+
rows: SyllabusRow[]
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const { rows } = Astro.props
|
|
17
|
+
---
|
|
18
|
+
<ol class="cs-rows" role="list">
|
|
19
|
+
{rows.map((row) => (
|
|
20
|
+
<li class:list={['cs-row', `cs-row-${row.state}`, row.href && 'cs-row-linked']}>
|
|
21
|
+
<span class="cs-mark" aria-hidden="true">{row.state === 'done' ? <Icon name="check" /> : row.state === 'locked' ? <Icon name="lock" /> : row.n}</span>
|
|
22
|
+
<span class="cs-name">{row.href ? <a href={row.href}>{lessonTitle(row.n, row.name)}</a> : lessonTitle(row.n, row.name)}</span>
|
|
23
|
+
<span class="cs-word">
|
|
24
|
+
{row.state === 'done' && 'Done'}
|
|
25
|
+
{row.state === 'next' && 'Up next'}
|
|
26
|
+
{row.state === 'locked' && (
|
|
27
|
+
<>
|
|
28
|
+
{row.lockWord}
|
|
29
|
+
{row.lock?.reason === 'members' && <span class="cs-join">Join to watch</span>}
|
|
30
|
+
</>
|
|
31
|
+
)}
|
|
32
|
+
</span>
|
|
33
|
+
{clockOf(row.seconds) && <span class="cs-len">{clockOf(row.seconds)}</span>}
|
|
34
|
+
</li>
|
|
35
|
+
))}
|
|
36
|
+
</ol>
|
|
37
|
+
|
|
38
|
+
<style>
|
|
39
|
+
.cs-rows {
|
|
40
|
+
display: grid;
|
|
41
|
+
margin: 0;
|
|
42
|
+
padding: 0;
|
|
43
|
+
list-style: none;
|
|
44
|
+
border-top: 1px solid var(--line);
|
|
45
|
+
}
|
|
46
|
+
.cs-row {
|
|
47
|
+
position: relative;
|
|
48
|
+
display: grid;
|
|
49
|
+
grid-template-columns: 2rem minmax(0, 1fr) auto;
|
|
50
|
+
grid-template-areas: 'mark name len' 'mark word word';
|
|
51
|
+
gap: 0.125rem 0.875rem;
|
|
52
|
+
align-items: center;
|
|
53
|
+
padding: 0.875rem 0.5rem;
|
|
54
|
+
border-bottom: 1px solid var(--line);
|
|
55
|
+
}
|
|
56
|
+
.cs-row-linked:hover {
|
|
57
|
+
background: color-mix(in srgb, var(--ink) 5%, transparent);
|
|
58
|
+
}
|
|
59
|
+
.cs-mark {
|
|
60
|
+
grid-area: mark;
|
|
61
|
+
display: inline-grid;
|
|
62
|
+
place-items: center;
|
|
63
|
+
width: 2rem;
|
|
64
|
+
height: 2rem;
|
|
65
|
+
border: 1.5px solid var(--line-strong);
|
|
66
|
+
border-radius: 50%;
|
|
67
|
+
color: var(--muted);
|
|
68
|
+
font-size: var(--text-sm);
|
|
69
|
+
font-weight: 700;
|
|
70
|
+
font-variant-numeric: tabular-nums;
|
|
71
|
+
}
|
|
72
|
+
.cs-row-done .cs-mark {
|
|
73
|
+
border-color: var(--button);
|
|
74
|
+
background: var(--button);
|
|
75
|
+
color: var(--button-ink);
|
|
76
|
+
}
|
|
77
|
+
.cs-row-next .cs-mark {
|
|
78
|
+
border-color: var(--accent);
|
|
79
|
+
color: var(--ink);
|
|
80
|
+
}
|
|
81
|
+
.cs-name {
|
|
82
|
+
grid-area: name;
|
|
83
|
+
min-width: 0;
|
|
84
|
+
font-weight: 600;
|
|
85
|
+
line-height: 1.35;
|
|
86
|
+
}
|
|
87
|
+
.cs-name a {
|
|
88
|
+
color: var(--ink);
|
|
89
|
+
text-decoration: none;
|
|
90
|
+
}
|
|
91
|
+
.cs-name a::after {
|
|
92
|
+
content: '';
|
|
93
|
+
position: absolute;
|
|
94
|
+
inset: 0;
|
|
95
|
+
}
|
|
96
|
+
.cs-name a:focus-visible {
|
|
97
|
+
outline: none;
|
|
98
|
+
}
|
|
99
|
+
.cs-row-linked:focus-within {
|
|
100
|
+
outline: 3px solid var(--link);
|
|
101
|
+
outline-offset: -3px;
|
|
102
|
+
}
|
|
103
|
+
.cs-row-linked:hover .cs-name a {
|
|
104
|
+
text-decoration: underline;
|
|
105
|
+
}
|
|
106
|
+
.cs-word {
|
|
107
|
+
grid-area: word;
|
|
108
|
+
display: flex;
|
|
109
|
+
flex-wrap: wrap;
|
|
110
|
+
gap: 0 0.75rem;
|
|
111
|
+
color: var(--muted);
|
|
112
|
+
font-size: var(--text-sm);
|
|
113
|
+
}
|
|
114
|
+
.cs-word:empty {
|
|
115
|
+
display: none;
|
|
116
|
+
}
|
|
117
|
+
.cs-row-next .cs-word,
|
|
118
|
+
.cs-row-done .cs-word {
|
|
119
|
+
color: var(--ink);
|
|
120
|
+
font-weight: 700;
|
|
121
|
+
}
|
|
122
|
+
.cs-join {
|
|
123
|
+
color: var(--link);
|
|
124
|
+
font-weight: 700;
|
|
125
|
+
}
|
|
126
|
+
.cs-len {
|
|
127
|
+
grid-area: len;
|
|
128
|
+
color: var(--muted);
|
|
129
|
+
font-size: var(--text-sm);
|
|
130
|
+
font-variant-numeric: tabular-nums;
|
|
131
|
+
}
|
|
132
|
+
@media (min-width: 48rem) {
|
|
133
|
+
.cs-row {
|
|
134
|
+
grid-template-columns: 2rem minmax(0, 1fr) auto 3.5rem;
|
|
135
|
+
grid-template-areas: 'mark name word len';
|
|
136
|
+
gap: 0 1rem;
|
|
137
|
+
padding: 0.875rem 0.75rem;
|
|
138
|
+
}
|
|
139
|
+
.cs-word {
|
|
140
|
+
justify-content: flex-end;
|
|
141
|
+
}
|
|
142
|
+
.cs-len {
|
|
143
|
+
text-align: right;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
</style>
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
// A Course as its syllabus and outline layouts draw it (board D2), and the
|
|
2
|
+
// course address both the Course and the Lesson sections read their course
|
|
3
|
+
// from.
|
|
4
|
+
//
|
|
5
|
+
// The course is the one at this address (`/<courses base>/<course>`, and a
|
|
6
|
+
// lesson's `/<courses base>/<course>/<lesson>`, the base the course type's
|
|
7
|
+
// `url_base`), or the section's `options.courseSlug` on a page that pins one.
|
|
8
|
+
// It is read through lib/visitor.ts: as the visitor while one is signed in
|
|
9
|
+
// (each lesson's Done and the course's bar, the locks as that visitor meets
|
|
10
|
+
// them), else as the public reader. The section's own data carries no course.
|
|
11
|
+
|
|
12
|
+
import type { Section } from '@backgold/content'
|
|
13
|
+
import type { ContentAccessLevel, CourseDetail, CourseLesson, CourseProgress, EntryLock, Visitor } from '#contract/content-api'
|
|
14
|
+
import { safeHref, safeSrc, signInHref, signOutHref } from '@backgold/astro/server'
|
|
15
|
+
import { COURSE_TYPE_KEY, finishedOn, lockWordOf, whoCanWatch } from '../../../lib/academy'
|
|
16
|
+
import { SLUG, academyReads, type AcademyReads } from '../../../lib/visitor'
|
|
17
|
+
|
|
18
|
+
export interface AcademyContext {
|
|
19
|
+
locals: App.Locals
|
|
20
|
+
url: URL
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** The course (and lesson) this address names under the course type's base, or null. */
|
|
24
|
+
export async function routeOf(astro: AcademyContext): Promise<{ course: string; lesson: string | null } | null> {
|
|
25
|
+
const client = astro.locals.backgold.client
|
|
26
|
+
if (!client) return null
|
|
27
|
+
const base = (await client.types()).types.find((t) => t.key === COURSE_TYPE_KEY)?.url_base
|
|
28
|
+
let parts: string[]
|
|
29
|
+
try {
|
|
30
|
+
parts = astro.url.pathname.split('/').filter(Boolean).map(decodeURIComponent)
|
|
31
|
+
} catch {
|
|
32
|
+
return null
|
|
33
|
+
}
|
|
34
|
+
if (!base || parts[0] !== base || !parts[1] || parts.length > 3) return null
|
|
35
|
+
return { course: parts[1], lesson: parts[2] ?? null }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** The section's pinned course (`options.courseSlug`), or null when it pins none. */
|
|
39
|
+
export function pinnedCourseOf(section: Section): string | null {
|
|
40
|
+
const slug = section.options?.courseSlug
|
|
41
|
+
return typeof slug === 'string' && SLUG.test(slug) ? slug : null
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export type LessonState = 'done' | 'next' | 'locked' | 'open'
|
|
45
|
+
|
|
46
|
+
export interface SyllabusRow {
|
|
47
|
+
n: number
|
|
48
|
+
slug: string
|
|
49
|
+
/** The lesson's own title, "Decide what you want". */
|
|
50
|
+
name: string
|
|
51
|
+
href: string | null
|
|
52
|
+
seconds: number | null
|
|
53
|
+
state: LessonState
|
|
54
|
+
lock: EntryLock | null
|
|
55
|
+
/** The lock's word ("For members", "Sign in to watch"); null on an open lesson. */
|
|
56
|
+
lockWord: string | null
|
|
57
|
+
access: ContentAccessLevel
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface CourseView {
|
|
61
|
+
title: string
|
|
62
|
+
summary: string | null
|
|
63
|
+
cover: string | null
|
|
64
|
+
/** The courses list (the course address's parent), for the breadcrumb. */
|
|
65
|
+
coursesHref: string | null
|
|
66
|
+
lessons: number
|
|
67
|
+
seconds: number | null
|
|
68
|
+
access: ContentAccessLevel
|
|
69
|
+
visitor: Visitor | null
|
|
70
|
+
/** The visitor's place; null signed out. */
|
|
71
|
+
progress: CourseProgress | null
|
|
72
|
+
rows: SyllabusRow[]
|
|
73
|
+
/** The lesson this visitor finished last and when ("Lesson 4 finished on Tuesday"); null signed out or before any `completed_at`. */
|
|
74
|
+
lastFinished: { n: number; on: string } | null
|
|
75
|
+
/** The lesson the head's button opens ("Continue · Lesson 5", "Start · Lesson 1"); null when there is none to open. */
|
|
76
|
+
next: { row: SyllabusRow; verb: 'Continue' | 'Start' } | null
|
|
77
|
+
/** "Anyone signed in with their email". */
|
|
78
|
+
whoCanWatch: string
|
|
79
|
+
/** The lessons whose rule is not the course's: "Lesson 9", "Members of <org>". */
|
|
80
|
+
exceptions: { n: number; who: string }[]
|
|
81
|
+
signIn: string
|
|
82
|
+
signOut: string
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function rowOf(lesson: CourseLesson, n: number, progress: CourseProgress | null): SyllabusRow {
|
|
86
|
+
const state: LessonState = lesson.locked ? 'locked' : lesson.completed ? 'done' : progress?.next_lesson_slug === lesson.slug ? 'next' : 'open'
|
|
87
|
+
return {
|
|
88
|
+
n,
|
|
89
|
+
slug: lesson.slug,
|
|
90
|
+
name: lesson.title,
|
|
91
|
+
href: safeHref(lesson.url),
|
|
92
|
+
seconds: lesson.duration_seconds,
|
|
93
|
+
state,
|
|
94
|
+
lock: lesson.locked ? lesson.lock : null,
|
|
95
|
+
lockWord: lesson.locked && lesson.lock ? lockWordOf(lesson.lock) : null,
|
|
96
|
+
access: lesson.access,
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** The newest `completed_at` among the visitor's finished lessons. */
|
|
101
|
+
function lastFinishedOf(lessons: CourseLesson[], visitor: Visitor | null): { n: number; on: string } | null {
|
|
102
|
+
if (!visitor) return null
|
|
103
|
+
let best: { n: number; at: number } | null = null
|
|
104
|
+
for (const [i, lesson] of lessons.entries()) {
|
|
105
|
+
const at = lesson.completed && lesson.completed_at !== null ? Date.parse(lesson.completed_at) : NaN
|
|
106
|
+
if (!Number.isNaN(at) && (best === null || at > best.at)) best = { n: i + 1, at }
|
|
107
|
+
}
|
|
108
|
+
if (best === null) return null
|
|
109
|
+
const on = finishedOn(new Date(best.at).toISOString())
|
|
110
|
+
return on ? { n: best.n, on } : null
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** The course as the layouts draw it, for this visitor (null signed out), this page's address and the organization's name. */
|
|
114
|
+
export function courseView(course: CourseDetail, visitor: Visitor | null, path: string, orgName: string | null): CourseView {
|
|
115
|
+
const lessons = [...course.lessons].sort((a, b) => a.position - b.position)
|
|
116
|
+
const progress = visitor ? course.progress : null
|
|
117
|
+
const rows = lessons.map((lesson, i) => rowOf(lesson, i + 1, progress))
|
|
118
|
+
const nextRow = progress ? rows.find((r) => r.slug === progress.next_lesson_slug) : rows[0]
|
|
119
|
+
const coursesPath = course.url.replace(/\/[^/]+\/?$/, '')
|
|
120
|
+
return {
|
|
121
|
+
title: course.title,
|
|
122
|
+
summary: course.summary,
|
|
123
|
+
cover: course.hero ? safeSrc(course.hero.url) : null,
|
|
124
|
+
coursesHref: coursesPath ? safeHref(coursesPath) : null,
|
|
125
|
+
lessons: course.lesson_count || lessons.length,
|
|
126
|
+
seconds: course.total_seconds,
|
|
127
|
+
access: course.access,
|
|
128
|
+
visitor,
|
|
129
|
+
progress,
|
|
130
|
+
rows,
|
|
131
|
+
lastFinished: lastFinishedOf(lessons, progress ? visitor : null),
|
|
132
|
+
next: nextRow ? { row: nextRow, verb: progress && progress.completed > 0 ? 'Continue' : 'Start' } : null,
|
|
133
|
+
whoCanWatch: whoCanWatch(course.access, orgName, course.lock?.tag_label ?? null),
|
|
134
|
+
exceptions: rows.filter((r) => r.access !== course.access).map((r) => ({ n: r.n, who: whoCanWatch(r.access, orgName, r.lock?.tag_label ?? null) })),
|
|
135
|
+
signIn: signInHref(path, course.title),
|
|
136
|
+
signOut: signOutHref(path),
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** The course this section names (its pin, else the address), read for this visitor; null when there is none. */
|
|
141
|
+
export async function courseOf(section: Section, astro: AcademyContext, reads: AcademyReads = academyReads(astro)): Promise<CourseView | null> {
|
|
142
|
+
const slug = pinnedCourseOf(section) ?? (await routeOf(astro))?.course ?? null
|
|
143
|
+
if (!slug) return null
|
|
144
|
+
const found = await reads.course(slug)
|
|
145
|
+
return found ? courseView(found.course, reads.visitor, astro.url.pathname, reads.orgName) : null
|
|
146
|
+
}
|