diff --git a/Dockerfile b/Dockerfile index 757e4cf..484f97b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,7 @@ FROM nginx:1.27-alpine COPY nginx.conf /etc/nginx/conf.d/default.conf COPY faelle.html /usr/share/nginx/html/index.html -COPY faelle.html /usr/share/nginx/html/faelle.html +COPY faelle.html manifest.webmanifest sw.js /usr/share/nginx/html/ +COPY icons /usr/share/nginx/html/icons EXPOSE 80 HEALTHCHECK --interval=30s --timeout=3s CMD wget -qO- http://127.0.0.1/ >/dev/null || exit 1 diff --git a/faelle.html b/faelle.html index 9d4db57..86959a4 100644 --- a/faelle.html +++ b/faelle.html @@ -66,6 +66,14 @@ td.n{color:var(--mu)}td.t{font-weight:700;font-size:20px;color:var(--c)} .stats b{display:block;font-family:'Fredoka',sans-serif;font-size:26px} @media (prefers-reduced-motion:reduce){*{transition:none!important}} + + + + + + + +
@@ -227,5 +235,10 @@ function quiz(k){ } home(); + diff --git a/icons/apple-touch-icon.png b/icons/apple-touch-icon.png new file mode 100644 index 0000000..a42e372 Binary files /dev/null and b/icons/apple-touch-icon.png differ diff --git a/icons/icon-192.png b/icons/icon-192.png new file mode 100644 index 0000000..3a8bcbc Binary files /dev/null and b/icons/icon-192.png differ diff --git a/icons/icon-512.png b/icons/icon-512.png new file mode 100644 index 0000000..031cdee Binary files /dev/null and b/icons/icon-512.png differ diff --git a/icons/icon-maskable-512.png b/icons/icon-maskable-512.png new file mode 100644 index 0000000..8c0263f Binary files /dev/null and b/icons/icon-maskable-512.png differ diff --git a/manifest.webmanifest b/manifest.webmanifest new file mode 100644 index 0000000..293e052 --- /dev/null +++ b/manifest.webmanifest @@ -0,0 +1,19 @@ +{ + "name": "Fälle – Akkusativ, Dativ, Genitiv", + "short_name": "Fälle", + "description": "تعلّم Akkusativ, Dativ, Genitiv بالألوان، خطوة بخطوة.", + "lang": "ar", + "dir": "rtl", + "id": "/", + "start_url": "/", + "scope": "/", + "display": "standalone", + "orientation": "portrait", + "background_color": "#F5F3FF", + "theme_color": "#8B6CFF", + "icons": [ + { "src": "/icons/icon-192.png", "sizes": "192x192", "type": "image/png", "purpose": "any" }, + { "src": "/icons/icon-512.png", "sizes": "512x512", "type": "image/png", "purpose": "any" }, + { "src": "/icons/icon-maskable-512.png", "sizes": "512x512", "type": "image/png", "purpose": "maskable" } + ] +} diff --git a/nginx.conf b/nginx.conf index 9ba3a73..637c723 100644 --- a/nginx.conf +++ b/nginx.conf @@ -6,7 +6,21 @@ server { charset utf-8; gzip on; - gzip_types text/html text/css application/javascript; + gzip_types text/html text/css application/javascript application/manifest+json; + + location = /manifest.webmanifest { + default_type application/manifest+json; + add_header Cache-Control "no-cache"; + } + + location = /sw.js { + add_header Cache-Control "no-cache"; + add_header Service-Worker-Allowed "/"; + } + + location /icons/ { + add_header Cache-Control "public, max-age=604800"; + } location / { try_files $uri $uri/ /index.html; diff --git a/sw.js b/sw.js new file mode 100644 index 0000000..747af8d --- /dev/null +++ b/sw.js @@ -0,0 +1,40 @@ +const CACHE = 'faelle-v1'; +const SHELL = ['/', '/manifest.webmanifest', '/icons/icon-192.png', '/icons/icon-512.png']; + +self.addEventListener('install', (e) => { + e.waitUntil(caches.open(CACHE).then((c) => c.addAll(SHELL)).then(() => self.skipWaiting())); +}); + +self.addEventListener('activate', (e) => { + e.waitUntil( + caches.keys() + .then((keys) => Promise.all(keys.filter((k) => k !== CACHE).map((k) => caches.delete(k)))) + .then(() => self.clients.claim()) + ); +}); + +self.addEventListener('fetch', (e) => { + const req = e.request; + if (req.method !== 'GET') return; + + // Pages: network first so updates show up, cache as offline fallback. + if (req.mode === 'navigate') { + e.respondWith( + fetch(req) + .then((res) => { const copy = res.clone(); caches.open(CACHE).then((c) => c.put('/', copy)); return res; }) + .catch(() => caches.match('/')) + ); + return; + } + + // Everything else (icons, Google Fonts): cache first, fill cache on miss. + e.respondWith( + caches.match(req).then((hit) => hit || fetch(req).then((res) => { + if (res.ok || res.type === 'opaque') { + const copy = res.clone(); + caches.open(CACHE).then((c) => c.put(req, copy)); + } + return res; + })) + ); +});