@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,105 @@
|
|
|
1
|
+
// Reading a section from the Content API: its rows, media and links, each
|
|
2
|
+
// address already checked.
|
|
3
|
+
|
|
4
|
+
import type { Entry, Section } from '@backgold/content'
|
|
5
|
+
import { relFor, safeHref, safeSrc } from '@backgold/astro/server'
|
|
6
|
+
import { text } from './format'
|
|
7
|
+
|
|
8
|
+
export type Row = Record<string, unknown>
|
|
9
|
+
|
|
10
|
+
/** `data.items` rows that are objects. */
|
|
11
|
+
export function rows(section: Section): Row[] {
|
|
12
|
+
return (section.data?.items ?? []).filter((item): item is Row => !!item && typeof item === 'object' && !Array.isArray(item))
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** An array field of a row, as rows. */
|
|
16
|
+
export function nested(row: Row, key: string): Row[] {
|
|
17
|
+
const value = row[key]
|
|
18
|
+
return Array.isArray(value) ? value.filter((item): item is Row => !!item && typeof item === 'object' && !Array.isArray(item)) : []
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface Media {
|
|
22
|
+
url: string
|
|
23
|
+
alt: string
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** The first of `keys` the section has media for, with a safe address. */
|
|
27
|
+
export function media(section: Section, ...keys: string[]): Media | null {
|
|
28
|
+
for (const key of keys) {
|
|
29
|
+
const m = section.media?.[key]
|
|
30
|
+
const url = m ? safeSrc(m.url) : null
|
|
31
|
+
if (url) return { url, alt: typeof m?.alt === 'string' ? m.alt : '' }
|
|
32
|
+
}
|
|
33
|
+
return null
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* A Hero's or an About's photo treatment (`options.photoStyle`), as
|
|
38
|
+
* BackGold's own blocks read it: 'photo' (the default) crops the picture to
|
|
39
|
+
* fill its frame; 'badge' and 'plain' show the whole picture (a logo, an
|
|
40
|
+
* illustration), on the frame's surface or on nothing.
|
|
41
|
+
*/
|
|
42
|
+
export function photoStyleOf(section: Section): 'photo' | 'badge' | 'plain' {
|
|
43
|
+
const style = section.options?.photoStyle
|
|
44
|
+
return style === 'badge' || style === 'plain' ? style : 'photo'
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* A Hero's photo: the first of `keys` the section has media for, its alt text
|
|
49
|
+
* the section's `copy.imageAlt` (empty when the section has none).
|
|
50
|
+
*/
|
|
51
|
+
export function heroPhoto(section: Section, ...keys: string[]): Media | null {
|
|
52
|
+
const m = media(section, ...keys)
|
|
53
|
+
return m ? { url: m.url, alt: text(section.copy.imageAlt) ?? '' } : null
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface Link {
|
|
57
|
+
label: string
|
|
58
|
+
href: string
|
|
59
|
+
rel: 'noopener' | undefined
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** A link with a label and a safe address, or null. */
|
|
63
|
+
export function linkOf(label: unknown, href: unknown): Link | null {
|
|
64
|
+
const name = text(label)
|
|
65
|
+
const safe = safeHref(href, { anchors: true })
|
|
66
|
+
return name && safe ? { label: name, href: safe, rel: relFor(safe) } : null
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** The section's links, unsafe ones left out. */
|
|
70
|
+
export function links(section: Section): Link[] {
|
|
71
|
+
return (section.links ?? []).map((l) => linkOf(l.label, l.url)).filter((l): l is Link => l !== null)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** A card for an entry: what EntryCard shows. */
|
|
75
|
+
export interface Card {
|
|
76
|
+
title: string
|
|
77
|
+
href: string | null
|
|
78
|
+
summary: string | null
|
|
79
|
+
image: Media | null
|
|
80
|
+
/** The entry's category, drawn as a chip: a `category` term first, else its first term. */
|
|
81
|
+
category: string | null
|
|
82
|
+
date: string | null
|
|
83
|
+
/** What the card says under its summary, before the day it was published. */
|
|
84
|
+
meta: string | null
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function entryCard(entry: Entry): Card {
|
|
88
|
+
const image = entry.hero ? safeSrc(entry.hero.url) : null
|
|
89
|
+
const category = entry.terms.find((t) => t.taxonomy === 'category') ?? entry.terms[0]
|
|
90
|
+
return {
|
|
91
|
+
title: entry.title,
|
|
92
|
+
href: entry.url ? safeHref(entry.url) : null,
|
|
93
|
+
summary: entry.summary,
|
|
94
|
+
image: image ? { url: image, alt: '' } : null,
|
|
95
|
+
category: category?.label ?? null,
|
|
96
|
+
date: entry.publish_at,
|
|
97
|
+
meta: null,
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** A page opens with a Hero that has a headline: that headline is its <h1>, and the Hero leads the page. */
|
|
102
|
+
export function leadsWithHero(sections: Section[]): boolean {
|
|
103
|
+
const first = sections[0]
|
|
104
|
+
return first?.type === 'Hero' && text(first.copy.headline) !== null
|
|
105
|
+
}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
// The organization's volunteer shifts as the kit's volunteer pages draw them
|
|
2
|
+
// (`/volunteer`, the open-shifts list src/routes/catch-all.astro draws when
|
|
3
|
+
// the site has no page of its own at that address, and
|
|
4
|
+
// src/routes/volunteer-shift.astro, `/volunteer/<slug>`), read from the
|
|
5
|
+
// Content API's `GET /shifts`: every open shift, soonest first, each with its
|
|
6
|
+
// counts, its state (`open`, `full`, `waitlist`, `closed`), what it belongs to
|
|
7
|
+
// and BackGold's sign-up card for it: `signup_embed.iframe`, the frame the
|
|
8
|
+
// shift's page sets in the site's look, and `signup_url`, the same card as a
|
|
9
|
+
// page of its own on BackGold, which a page links to when the api sends no
|
|
10
|
+
// frame (an api older than the frame). The counts move between publishes,
|
|
11
|
+
// so the pages draw them as built and read them again from `GET /shifts/live`
|
|
12
|
+
// after load (components/volunteer/ShiftLive.astro).
|
|
13
|
+
//
|
|
14
|
+
// Times are the organization's zone's (the row's `timezone`), as lib/format.ts
|
|
15
|
+
// writes them: "6:00 PM to 8:00 PM CDT" for a shift that ends the day it
|
|
16
|
+
// starts.
|
|
17
|
+
|
|
18
|
+
import type { Areas, BackgoldContent, SectionEmbed, ShiftsListRow } from '@backgold/content'
|
|
19
|
+
import { safeHref } from '@backgold/astro/server'
|
|
20
|
+
import { whenOf, monthName, type When } from '../components/sections/EventsList/events'
|
|
21
|
+
|
|
22
|
+
export const VOLUNTEER_PATH = '/volunteer'
|
|
23
|
+
|
|
24
|
+
/** A shift's own page on this site. */
|
|
25
|
+
export const shiftPath = (slug: string): string => `${VOLUNTEER_PATH}/${encodeURIComponent(slug)}`
|
|
26
|
+
|
|
27
|
+
/** A row of `GET /shifts` with the sign-up frame the api sends beside it; an older api sends none. */
|
|
28
|
+
export type ShiftRow = ShiftsListRow & { signup_embed?: { iframe: string | null } | null }
|
|
29
|
+
|
|
30
|
+
/** The most shifts the list reads (four pages of 50). */
|
|
31
|
+
const MOST = 200
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Every open shift, soonest first, walking the feed's cursor up to MOST rows;
|
|
35
|
+
* null when the api does not serve the feed (an older api) or the read fails.
|
|
36
|
+
*/
|
|
37
|
+
export async function openShifts(client: BackgoldContent): Promise<ShiftRow[] | null> {
|
|
38
|
+
const rows: ShiftRow[] = []
|
|
39
|
+
let cursor: string | undefined
|
|
40
|
+
try {
|
|
41
|
+
do {
|
|
42
|
+
const page = await client.shifts({ limit: 50, ...(cursor ? { cursor } : {}) })
|
|
43
|
+
rows.push(...(page.shifts as ShiftRow[]))
|
|
44
|
+
cursor = page.next_cursor ?? undefined
|
|
45
|
+
} while (cursor && rows.length < MOST)
|
|
46
|
+
} catch {
|
|
47
|
+
return rows.length > 0 ? rows : null
|
|
48
|
+
}
|
|
49
|
+
return rows.slice(0, MOST)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** The areas of a volunteer page: those that show on every page and on pages that hold events (an EventsList holds an event). Null when the read fails. */
|
|
53
|
+
export async function volunteerAreas(client: BackgoldContent): Promise<Areas | null> {
|
|
54
|
+
try {
|
|
55
|
+
return (await client.areas({ holds: ['event'] })).areas
|
|
56
|
+
} catch {
|
|
57
|
+
return null
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** The shift's sign-up frame as ModuleFrame takes it, or null when the api sent none. */
|
|
62
|
+
export function signupEmbedOf(shift: ShiftRow): SectionEmbed | null {
|
|
63
|
+
const iframe = shift.signup_embed?.iframe
|
|
64
|
+
return typeof iframe === 'string' && iframe !== '' ? { iframe, script: '' } : null
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** A shift's button, by its state: words, and whether it draws as the quiet button (nothing to sign up for). */
|
|
68
|
+
export const SHIFT_ACTIONS: Record<ShiftsListRow['state'], { label: string; quiet: boolean }> = {
|
|
69
|
+
open: { label: 'Sign up', quiet: false },
|
|
70
|
+
waitlist: { label: 'Join the waitlist', quiet: false },
|
|
71
|
+
full: { label: 'Full', quiet: true },
|
|
72
|
+
closed: { label: 'Closed', quiet: true },
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** The most spots drawn as dots; past that, the words alone. */
|
|
76
|
+
export const MOST_DOTS = 24
|
|
77
|
+
|
|
78
|
+
/** One shift as the volunteer pages draw it. */
|
|
79
|
+
export interface ShiftView {
|
|
80
|
+
id: string
|
|
81
|
+
slug: string
|
|
82
|
+
title: string
|
|
83
|
+
startsAt: string
|
|
84
|
+
when: When | null
|
|
85
|
+
/** "6:00 PM to 8:00 PM CDT", the start's time alone across days, or null for an undated row. */
|
|
86
|
+
time: string | null
|
|
87
|
+
place: string | null
|
|
88
|
+
/** The shift's page on this site. */
|
|
89
|
+
href: string
|
|
90
|
+
state: ShiftsListRow['state']
|
|
91
|
+
action: { label: string; quiet: boolean }
|
|
92
|
+
signedUp: number
|
|
93
|
+
capacity: number | null
|
|
94
|
+
/** The counts in words, as the live script writes them too: "6 of 10 filled · 4 spots left". */
|
|
95
|
+
words: string
|
|
96
|
+
/** One per spot (`true` taken), up to MOST_DOTS; empty with no capacity or more spots than that. */
|
|
97
|
+
dots: boolean[]
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** A shift's counts in words: "6 of 10 filled · 4 spots left", "10 of 10 filled · Full", "3 signed up", or '' with no one yet and no capacity. */
|
|
101
|
+
export function countWords(signedUp: number, capacity: number | null): string {
|
|
102
|
+
if (capacity !== null && capacity > 0) {
|
|
103
|
+
const left = capacity - signedUp
|
|
104
|
+
return `${signedUp} of ${capacity} filled · ${left > 0 ? `${left} ${left === 1 ? 'spot' : 'spots'} left` : 'Full'}`
|
|
105
|
+
}
|
|
106
|
+
return signedUp > 0 ? `${signedUp} signed up` : ''
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function shiftView(shift: ShiftRow): ShiftView {
|
|
110
|
+
const when = whenOf(shift.starts_at, shift.timezone)
|
|
111
|
+
const end = whenOf(shift.ends_at, shift.timezone)
|
|
112
|
+
const sameDay = when && end && when.year === end.year && when.monthIndex === end.monthIndex && when.day === end.day
|
|
113
|
+
const capacity = typeof shift.capacity === 'number' && shift.capacity > 0 ? shift.capacity : null
|
|
114
|
+
const signedUp = Math.max(0, shift.signed_up)
|
|
115
|
+
return {
|
|
116
|
+
id: shift.id,
|
|
117
|
+
slug: shift.slug,
|
|
118
|
+
title: shift.title,
|
|
119
|
+
startsAt: shift.starts_at,
|
|
120
|
+
when,
|
|
121
|
+
time: when?.clock && sameDay && end?.time ? `${when.clock} to ${end.time}` : (when?.time ?? null),
|
|
122
|
+
place: shift.location?.trim() || null,
|
|
123
|
+
href: shiftPath(shift.slug),
|
|
124
|
+
state: shift.state,
|
|
125
|
+
action: SHIFT_ACTIONS[shift.state] ?? SHIFT_ACTIONS.closed,
|
|
126
|
+
signedUp,
|
|
127
|
+
capacity,
|
|
128
|
+
words: countWords(signedUp, capacity),
|
|
129
|
+
dots: capacity !== null && capacity <= MOST_DOTS ? Array.from({ length: capacity }, (_, i) => i < signedUp) : [],
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** The words of every state's button, for the live script. */
|
|
134
|
+
export const SHIFT_ACTION_LABELS = JSON.stringify(Object.fromEntries(Object.entries(SHIFT_ACTIONS).map(([state, a]) => [state, a.label])))
|
|
135
|
+
|
|
136
|
+
/** A run of shifts in one week, Monday to Sunday in the shifts' own calendar. */
|
|
137
|
+
export interface ShiftWeek {
|
|
138
|
+
/** The Monday, "2026-11-02", which the script matches to say This week and Next week; '' for undated rows. */
|
|
139
|
+
key: string
|
|
140
|
+
/** "Week of Nov 2"; null for undated rows. */
|
|
141
|
+
heading: string | null
|
|
142
|
+
/** "Nov 2 to 8", "Nov 30 to Dec 6"; null for undated rows. */
|
|
143
|
+
dates: string | null
|
|
144
|
+
shifts: ShiftView[]
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const short = (d: Date) => `${monthName(d.getUTCMonth()).slice(0, 3)} ${d.getUTCDate()}`
|
|
148
|
+
|
|
149
|
+
/** The shifts grouped by week, in their order; a week with no shift is not drawn. */
|
|
150
|
+
export function weeksOf(shifts: ShiftView[]): ShiftWeek[] {
|
|
151
|
+
const weeks: ShiftWeek[] = []
|
|
152
|
+
for (const shift of shifts) {
|
|
153
|
+
let monday: Date | null = null
|
|
154
|
+
if (shift.when) {
|
|
155
|
+
monday = new Date(Date.UTC(shift.when.year, shift.when.monthIndex, Number(shift.when.day)))
|
|
156
|
+
monday.setUTCDate(monday.getUTCDate() - ((monday.getUTCDay() + 6) % 7))
|
|
157
|
+
}
|
|
158
|
+
const key = monday ? monday.toISOString().slice(0, 10) : ''
|
|
159
|
+
const last = weeks[weeks.length - 1]
|
|
160
|
+
if (last && last.key === key) {
|
|
161
|
+
last.shifts.push(shift)
|
|
162
|
+
continue
|
|
163
|
+
}
|
|
164
|
+
let dates: string | null = null
|
|
165
|
+
if (monday) {
|
|
166
|
+
const sunday = new Date(monday)
|
|
167
|
+
sunday.setUTCDate(sunday.getUTCDate() + 6)
|
|
168
|
+
dates = `${short(monday)} to ${sunday.getUTCMonth() === monday.getUTCMonth() ? sunday.getUTCDate() : short(sunday)}`
|
|
169
|
+
}
|
|
170
|
+
weeks.push({ key, heading: monday ? `Week of ${short(monday)}` : null, dates, shifts: [shift] })
|
|
171
|
+
}
|
|
172
|
+
return weeks
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** A maps search for the shift's place, or null with none. */
|
|
176
|
+
export function mapLinkOf(place: string | null): string | null {
|
|
177
|
+
return place ? safeHref(`https://www.google.com/maps/search/?api=1&query=${encodeURIComponent(place)}`) : null
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const emitted = new WeakSet<Request>()
|
|
181
|
+
|
|
182
|
+
/** True the first time it is asked during one render, so a page carries one copy of the shifts' live script. */
|
|
183
|
+
export function firstShiftScript(request: Request): boolean {
|
|
184
|
+
if (emitted.has(request)) return false
|
|
185
|
+
emitted.add(request)
|
|
186
|
+
return true
|
|
187
|
+
}
|