Studies: add a Download Study Guide button to the study page, automatic from the linked series/book or chosen per study in admin; v2.35.0
Publish Container / build (push) Successful in 18m26s
Publish Container / build (push) Successful in 18m26s
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b48a81a00c
commit
82ce312898
6 files changed
+60
-3
No files matched your search
@@ -14,6 +14,9 @@ export interface StudyProgram {
|
||||
showOnHomepage?: boolean
|
||||
showNewTag?: boolean
|
||||
newTagLabel?: string
|
||||
// Which companion guide the study offers for download: '' = automatic (the guide of the series or
|
||||
// finished book linked to this study), 'none', 'primary', 'second', or 'book:<finished book id>'
|
||||
guideSource?: string
|
||||
// 'complete' = finished and self-paced (still open for enrollment). A study whose lessons
|
||||
// have all been released is treated as complete even if left as 'active'.
|
||||
status: 'active' | 'planned' | 'complete'
|
||||
@@ -700,3 +703,39 @@ export function getAllHighlights(content: Pick<SiteContent, 'podcastFeaturedLink
|
||||
...(content.finishedBooks ?? []).flatMap(book => book.highlights ?? []),
|
||||
]
|
||||
}
|
||||
|
||||
export interface StudyGuideLink {
|
||||
// Page id under /downloads/ (primary-guide, second-guide, book-guide--<id>)
|
||||
pageId: string
|
||||
title: string
|
||||
}
|
||||
|
||||
// The companion guide a study offers, either chosen explicitly in admin or found through the
|
||||
// series / finished book that is linked to the study.
|
||||
export function getStudyGuideLink(
|
||||
content: Pick<SiteContent, 'seriesStudySlug' | 'studyGuideTitle' | 'studyGuideUrl' | 'studyGuideDownloadUrl' | 'studyGuideAppleBooksUrl' | 'secondSeries' | 'finishedBooks'>,
|
||||
study: Pick<StudyProgram, 'slug' | 'guideSource'>,
|
||||
): StudyGuideLink | null {
|
||||
const source = study.guideSource ?? ''
|
||||
if (source === 'none') return null
|
||||
|
||||
const primary = (): StudyGuideLink | null =>
|
||||
content.studyGuideTitle && (content.studyGuideUrl || content.studyGuideDownloadUrl || content.studyGuideAppleBooksUrl)
|
||||
? { pageId: 'primary-guide', title: content.studyGuideTitle }
|
||||
: null
|
||||
const second = (): StudyGuideLink | null =>
|
||||
content.secondSeries?.guide?.title ? { pageId: 'second-guide', title: content.secondSeries.guide.title } : null
|
||||
const book = (id: string): StudyGuideLink | null => {
|
||||
const found = (content.finishedBooks ?? []).find(b => b.id === id)
|
||||
return found?.guide?.title ? { pageId: `book-guide--${found.id}`, title: found.guide.title } : null
|
||||
}
|
||||
|
||||
if (source === 'primary') return primary()
|
||||
if (source === 'second') return second()
|
||||
if (source.startsWith('book:')) return book(source.slice('book:'.length))
|
||||
|
||||
if (content.seriesStudySlug && content.seriesStudySlug === study.slug) return primary()
|
||||
if (content.secondSeries?.studySlug && content.secondSeries.studySlug === study.slug) return second()
|
||||
const linkedBook = (content.finishedBooks ?? []).find(b => b.studySlug === study.slug && b.guide?.title)
|
||||
return linkedBook ? book(linkedBook.id) : null
|
||||
}
|
||||
Reference in new issue
Block a user