v1.1.0 — RSS feed, PWA, lesson comments, progress tracking + streaks

RSS Feed
- /feed.xml proxies the Anchor feed under the site's canonical domain
- Rewrites channel <link> and atom:link self-ref to the site URL
- Served with 30-min Cache-Control, reuses the existing episode cache

PWA
- vite-plugin-pwa installed; Workbox service worker auto-generated on build
- manifest.json inlined in vite.config.ts (name, icons, theme, standalone)
- pwa-192.png and pwa-512.png generated from existing book_icon.png
- StaleWhileRevalidate for /api/episodes and /api/questions; CacheFirst for images
- API, feed.xml, and uploads routes excluded from navigate fallback

Lesson Comments
- Import and wire StudySectionComments into ColossiansStudySectionPage
- Replaces the CommunityBoard in the Lesson Discussion section
- All routes and moderation already existed; only the render was missing

Progress Tracking + Streaks
- Mark-complete handler now records lastStudiedDate, currentStreak, longestStreak on the user record
- Streak increments on consecutive calendar days, resets on a gap
- /api/study-account/overview now returns streak fields
- Account page: 4-stat summary row (notes, streak 🔥, longest streak, member since)
- Per-study progress bars showing completedLessons/totalLessons with gold → green fill at 100%

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
nmemmert
2026-07-22 13:19:25 -04:00
parent 455f5c96b3
commit 1e4fe5f0e3
11 changed files with 4614 additions and 108 deletions
+8 -1
View File
@@ -3,6 +3,7 @@ import { sanitizeUrl } from '../study-helpers.js'
const RSS_FEED_URL = 'https://anchor.fm/s/11068d290/podcast/rss'
let episodesCache = null
let episodesCacheAt = 0
let rawXmlCache = null
const EPISODES_CACHE_TTL = 30 * 60 * 1000
function extractCdata(raw) {
@@ -40,7 +41,7 @@ function parseRssItems(xml, limit = Infinity) {
return items
}
async function fetchAllEpisodes() {
export async function fetchAllEpisodes() {
const now = Date.now()
if (episodesCache && (now - episodesCacheAt) < EPISODES_CACHE_TTL) {
return episodesCache
@@ -51,12 +52,18 @@ async function fetchAllEpisodes() {
clearTimeout(timeout)
if (!response.ok) throw new Error(`RSS fetch failed: ${response.status}`)
const xml = await response.text()
rawXmlCache = xml
const episodes = parseRssItems(xml)
episodesCache = episodes
episodesCacheAt = now
return episodes
}
export async function fetchRawFeedXml() {
await fetchAllEpisodes()
return rawXmlCache
}
function toSpotifyEpisodeEmbedUrl(urlValue) {
if (!urlValue) return ''
try {
+35
View File
@@ -0,0 +1,35 @@
import { fetchRawFeedXml } from './episodes.js'
import { getCanonicalBaseUrl } from '../email.js'
export function register(app) {
app.get('/feed.xml', async (_req, res) => {
try {
const xml = await fetchRawFeedXml()
if (!xml) {
res.status(503).send('Feed temporarily unavailable')
return
}
const baseUrl = getCanonicalBaseUrl().replace(/\/$/, '')
const feedUrl = `${baseUrl}/feed.xml`
// Rewrite channel <link> and <atom:link href> to our canonical domain
const rewritten = xml
.replace(
/<atom:link[^>]+rel="self"[^>]*\/>/,
`<atom:link href="${feedUrl}" rel="self" type="application/rss+xml"/>`
)
.replace(
/(<channel>[\s\S]*?<link>)[^<]*(\/link>)/,
`$1${baseUrl}$2`
)
res.set('Content-Type', 'application/rss+xml; charset=utf-8')
res.set('Cache-Control', 'public, max-age=1800')
res.send(rewritten)
} catch (err) {
console.error('[feed.xml]', err?.message ?? err)
res.status(502).send('Failed to fetch feed')
}
})
}
+3
View File
@@ -224,6 +224,9 @@ export function register(app) {
noteCount: Object.keys(notes).length,
memberSince: user.createdAt,
lastLoginAt: user.lastLoginAt,
currentStreak: user.currentStreak ?? 0,
longestStreak: user.longestStreak ?? 0,
lastStudiedDate: user.lastStudiedDate ?? null,
},
studies,
})
+11 -1
View File
@@ -205,11 +205,21 @@ export function register(app) {
state.studyProgressCache.set(user.id, progress)
queueUserProgressWrite(user.id)
// Streak tracking
const todayStr = new Date().toISOString().slice(0, 10)
const lastDate = user.lastStudiedDate ?? null
if (lastDate !== todayStr) {
const yesterday = new Date(Date.now() - 864e5).toISOString().slice(0, 10)
user.currentStreak = lastDate === yesterday ? (user.currentStreak ?? 0) + 1 : 1
user.longestStreak = Math.max(user.currentStreak, user.longestStreak ?? 0)
user.lastStudiedDate = todayStr
}
// Record first completion timestamp on the user record (additive, never overwrite)
if (!user.firstCompletionAt) {
user.firstCompletionAt = new Date().toISOString()
queueStudyUsersWrite()
}
queueStudyUsersWrite()
res.json({ ok: true, studySlug, completedSectionIds: studyProgress.completedSectionIds })
})