jellyfin-lessons/templates/lesson.typ
Engineering (agent-engineering) 8b9d156166 fix: make media-ref inline with block: false
raw() defaults to block mode which wraps output in <pre><code>,
breaking list-item rendering. block: false keeps it inline.

Addresses PR #9 review feedback.
2026-05-15 21:39:28 -07:00

90 lines
2.7 KiB
Typst

// lesson.typ — Typst template for homeschool lessons
// ============================================================
// This template produces clean, structured lesson documents.
// Designed to compile to HTML for rendering inside Jellyfin.
//
// Frontmatter convention (documented as comments at top of each lesson):
// // title: The Lesson Title
// // grade: 3
// // subject: Science
// // date: 2026-01-15
// // media: jellyfin://uuid-1, jellyfin://uuid-2
// // description: Short description of the lesson
//
// Usage:
// #import "lesson.typ": lesson-template, media-ref
// #show: doc => lesson-template(
// doc,
// title: "The Water Cycle",
// grade: "3",
// subject: "Science",
// date: "2026-01-15",
// media: (),
// description: "Learn about evaporation and condensation.",
// )
// Render a single Jellyfin media reference.
// Produces a <code data-lang="jellyfin-media"> element in HTML output
// that the Jellyfin plugin can parse and link to the player.
#let media-ref(id, title) = {
raw(lang: "jellyfin-media", id + "|" + title, block: false)
}
// Render a list of media references as a formatted section.
#let media-section(media-items) = {
if media-items.len() > 0 {
heading(level: 2)[Media]
for item in media-items {
list.item(media-ref(item.at(0), item.at(1)))
}
}
}
// The main lesson template.
// - body: The lesson content (passed via show rule)
// - title: Lesson title (string)
// - grade: Grade level (string, e.g. "3")
// - subject: Subject name (string)
// - date: Lesson date in YYYY-MM-DD format
// - media: Array of (id, title) pairs for linked Jellyfin media
// - description: Short description of the lesson
#let lesson-template(
body,
title: "Untitled Lesson",
grade: none,
subject: none,
date: none,
media: (),
description: none,
) = {
// Document metadata for PDF output
set document(title: title)
// Title — prominent heading
heading(level: 1, title)
// Metadata line: Grade X — Subject — Date
let meta-parts = ()
if grade != none { meta-parts.push([Grade ] + grade) }
if subject != none { meta-parts.push(subject) }
if date != none { meta-parts.push(date) }
if meta-parts.len() > 0 {
let sep = [ — ]
let meta-text = meta-parts.first()
for i in range(1, meta-parts.len()) {
meta-text += sep + meta-parts.at(i)
}
par(text(style: "italic", size: 0.9em, meta-text))
}
// Description paragraph
if description != none {
par([*Description:* ] + description)
}
// Lesson body content (renders user-authored sections, paragraphs, lists, etc.)
body
// Media references section — listed with identifiable jellyfin-media codes
media-section(media)
}