diff --git a/README.md b/README.md index 9e998c0..bcb0ca4 100644 --- a/README.md +++ b/README.md @@ -140,6 +140,18 @@ Bu kontrol, build çıktısında uzak script/style/module bağlantısı kalmadı --- +## PWA ve çevrimdışı kullanım + +GitHub Pages sürümü installable PWA olarak yayınlanır. Manifest, uygulama ikonları ve service worker build sırasında `dist/` içine dahil edilir. + +- `start_url` ve `scope` relative (`./`) tutulduğu için proje `/mathnote/` gibi GitHub Pages alt yollarında çalışır. +- İlk başarılı ziyarette uygulama shell'i, JavaScript/CSS, KaTeX fontları, manifest ve ikonlar precache edilir. +- Yeni build'de dosya içeriğinden yeni bir cache sürümü üretilir; service worker aktive olduğunda eski MathNote cache'leri temizlenir. +- Service worker yalnızca HTTP/HTTPS üzerinde kaydolur. Bu nedenle `dist/index.html` dosyasını doğrudan `file://` ile açma desteği korunur. +- Destekleyen tarayıcılar MathNote'u masaüstüne veya ana ekrana bağımsız uygulama olarak kurabilir. + +--- + ## GitHub Pages Repo, GitHub Pages üzerinde kaynak `index.html` dosyasını doğrudan yayınlamak yerine GitHub Actions ile build edilir. `.github/workflows/pages.yml` workflow'u: diff --git a/index.html b/index.html index 42ef209..bdfcb8b 100644 --- a/index.html +++ b/index.html @@ -4,6 +4,12 @@ Math Notebook + + + + + + diff --git a/public/icons/icon-192.png b/public/icons/icon-192.png new file mode 100644 index 0000000..5da2f4d Binary files /dev/null and b/public/icons/icon-192.png differ diff --git a/public/icons/icon-512.png b/public/icons/icon-512.png new file mode 100644 index 0000000..6400118 Binary files /dev/null and b/public/icons/icon-512.png differ diff --git a/public/manifest.webmanifest b/public/manifest.webmanifest new file mode 100644 index 0000000..1eed752 --- /dev/null +++ b/public/manifest.webmanifest @@ -0,0 +1,25 @@ +{ + "name": "MathNote – Interactive Mathematics Notebook", + "short_name": "MathNote", + "description": "Offline-capable interactive mathematics notebook", + "start_url": "./", + "scope": "./", + "display": "standalone", + "background_color": "#ffffff", + "theme_color": "#1971c2", + "orientation": "any", + "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 maskable" + } + ] +} diff --git a/scripts/build.mjs b/scripts/build.mjs index e1e0c94..be525e4 100644 --- a/scripts/build.mjs +++ b/scripts/build.mjs @@ -1,8 +1,12 @@ import { build } from 'esbuild'; -import { mkdir, readFile, rm, writeFile } from 'node:fs/promises'; +import { createHash } from 'node:crypto'; +import { cp, mkdir, readFile, readdir, rm, writeFile } from 'node:fs/promises'; +import { relative } from 'node:path'; const outdir = new URL('../dist/', import.meta.url); const templateUrl = new URL('../index.html', import.meta.url); +const publicDir = new URL('../public/', import.meta.url); +const serviceWorkerTemplateUrl = new URL('../src/sw.js', import.meta.url); await rm(outdir, { recursive: true, force: true }); await mkdir(outdir, { recursive: true }); @@ -25,6 +29,8 @@ await build({ } }); +await cp(publicDir, outdir, { recursive: true }); + let html = await readFile(templateUrl, 'utf8'); html = html.replace( '', @@ -32,7 +38,7 @@ html = html.replace( ); html = html.replace( '', - '