Add basic PWA support (#38) (#210)

* Add basic PWA support

See: https://github.com/gpxstudio/gpx.studio/issues/38

This will add a basic manifest.json file to the response that creates an
installable PWA.

It still needs to be internationalized.

* Refactor PWA integration and update dependencies

- Removed @vite-pwa/sveltekit dependency and related configurations from package.json and vite.config.ts.
- Added prebuild script to generate PWA manifest before build.
- Moved the manifest link to hooks.server.js and included Apple touch icon.
-Added images for various platforms. Images were generated with https://www.pwabuilder.com/imageGenerator

* use svg icon, fix urls, and remove generated manifest files

---------

Co-authored-by: jonherman <jonherman@gmail.com>
Co-authored-by: vcoppe <vianney.coppe@gmail.com>
This commit is contained in:
Jon Herman
2025-05-08 09:23:07 -07:00
committed by GitHub
parent e4f6dfbf78
commit 4e9d65089c
6 changed files with 641 additions and 156 deletions

View File

@@ -0,0 +1,23 @@
import fs from 'fs';
import { languages } from '$lib/languages';
function localizeManifest(manifestTemplateData: any, language: string) {
const localizedManifestFile = `static/${language}.manifest.webmanifest`;
const localizedStringsFile = `src/locales/${language}.json`;
const localizedStrings = JSON.parse(fs.readFileSync(localizedStringsFile, 'utf8'));
manifestTemplateData.description = localizedStrings.metadata.description;
manifestTemplateData.lang = language;
manifestTemplateData.start_url = `/${language}/app`;
manifestTemplateData.scope = `/${language}/app`;
manifestTemplateData.id = `https://gpx.studio/${language}/app`;
fs.writeFileSync(localizedManifestFile, JSON.stringify(manifestTemplateData, null, 2));
}
const manifestTemplateFile = 'static/en.manifest.webmanifest';
const manifestTemplateData = JSON.parse(fs.readFileSync(manifestTemplateFile, 'utf8'));
for (const language of Object.keys(languages)) {
if (language === 'en') continue;
localizeManifest(manifestTemplateData, language);
}