mirror of
https://github.com/supabase/supabase.git
synced 2026-05-09 02:09:50 -04:00
dda0b526ac
wip <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit # Release Notes * **New Features** * Added a new Learn application offering foundational Supabase courses with interactive documentation * Courses include Architecture, Authentication, Data Fundamentals, Security, Storage, Realtime, and Edge Functions * Chapter tracking and progress indicators for course completions * Responsive sidebar navigation with search/command menu * Theme switching support (light, dark, classic dark modes) * Mobile-friendly course interface <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Alan Daniel <stylesshjs@gmail.com> Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
37 lines
1.0 KiB
TypeScript
37 lines
1.0 KiB
TypeScript
import { allDocs } from 'contentlayer/generated'
|
|
import { normalizeSlug } from './get-next-page'
|
|
|
|
/**
|
|
* Gets the current chapter number from a doc
|
|
*/
|
|
export function getCurrentChapter(
|
|
slug: string
|
|
): { chapterNumber?: number; completionMessage?: string } | null {
|
|
const normalizedSlug = normalizeSlug(slug)
|
|
const doc = allDocs.find((doc) => normalizeSlug(doc.slugAsParams) === normalizedSlug)
|
|
|
|
if (!doc) {
|
|
return null
|
|
}
|
|
|
|
// Get chapterNumber from frontmatter first, then fallback to parsing from title
|
|
let chapterNumber: number | undefined = (doc as any)?.chapterNumber
|
|
if (!chapterNumber) {
|
|
// Try to extract chapter number from title (e.g., "2: CSS Styling" -> 2)
|
|
const chapterMatch = doc.title.match(/^(\d+):/)
|
|
chapterNumber = chapterMatch ? parseInt(chapterMatch[1], 10) : undefined
|
|
}
|
|
|
|
if (!chapterNumber) {
|
|
return null
|
|
}
|
|
|
|
// Use description as completion message, or generate a default one
|
|
const completionMessage = doc.description || undefined
|
|
|
|
return {
|
|
chapterNumber,
|
|
completionMessage,
|
|
}
|
|
}
|