Files
homepage/src/routes/[recipeLang=recipeLang]/+layout.ts
Alexander Bocken 9ff30b28cd feat: add PWA offline support for recipe pages
- Add service worker with caching for build assets, static files, images, and pages
- Add IndexedDB storage for recipes (brief and full data)
- Add offline-db API endpoint for bulk recipe download
- Add offline sync button component in header
- Add offline-shell page for direct navigation fallback
- Pre-cache __data.json for client-side navigation
- Add +page.ts universal load functions with IndexedDB fallback
- Add PWA manifest and icons for installability
- Update recipe page to handle missing data gracefully
2026-01-28 21:38:33 +01:00

35 lines
876 B
TypeScript

import { browser } from '$app/environment';
import { error } from '@sveltejs/kit';
export async function load({ params, data }) {
// Validate recipeLang parameter
if (params.recipeLang !== 'rezepte' && params.recipeLang !== 'recipes') {
throw error(404, 'Not found');
}
const lang = params.recipeLang === 'recipes' ? 'en' : 'de';
// Check if we're offline:
// 1. Browser reports offline (navigator.onLine === false)
// 2. Service worker returned offline flag (data.isOffline === true)
const isClientOffline = browser && (!navigator.onLine || data?.isOffline);
if (isClientOffline) {
// Return minimal data for offline mode
return {
session: null,
lang,
recipeLang: params.recipeLang,
isOffline: true
};
}
// Use server data when available (online mode)
return {
...data,
lang,
recipeLang: params.recipeLang,
isOffline: false
};
}