mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2025-11-05 14:01:11 +00:00
progress
This commit is contained in:
23
website/src/lib/scripts/pwa-manifest.ts
Normal file
23
website/src/lib/scripts/pwa-manifest.ts
Normal 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);
|
||||
}
|
||||
49
website/src/lib/scripts/sitemap.ts
Normal file
49
website/src/lib/scripts/sitemap.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import fs from 'fs';
|
||||
import { glob } from 'glob';
|
||||
import { languages } from '$lib/languages';
|
||||
|
||||
function getURLForLanguage(lang: string, path: string): string {
|
||||
return `https://gpx.studio${lang === 'en' ? '' : `/${lang}`}${path}`;
|
||||
}
|
||||
|
||||
function generateSitemap() {
|
||||
const pages = glob.sync('**/*.html', { cwd: 'build' }).map((page) => `/${page}`);
|
||||
|
||||
let sitemap = '<?xml version="1.0" encoding="UTF-8"?>\n';
|
||||
sitemap +=
|
||||
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">\n';
|
||||
|
||||
pages.forEach((page) => {
|
||||
const path = page.replace('/index.html', '').replace('.html', '');
|
||||
|
||||
const rootDir = path.split('/')[1];
|
||||
if (
|
||||
path.includes('embed') ||
|
||||
path.includes('404') ||
|
||||
languages[path] ||
|
||||
languages[rootDir]
|
||||
) {
|
||||
// Skip localized pages
|
||||
return;
|
||||
}
|
||||
|
||||
Object.keys(languages).forEach((language) => {
|
||||
sitemap += `<url>\n`;
|
||||
sitemap += ` <loc>${getURLForLanguage(language, path)}</loc>\n`;
|
||||
|
||||
Object.keys(languages).forEach((alternate) => {
|
||||
if (alternate === language) return;
|
||||
|
||||
sitemap += ` <xhtml:link rel="alternate" hreflang="${alternate}" href="${getURLForLanguage(alternate, path)}" />\n`;
|
||||
});
|
||||
|
||||
sitemap += `</url>\n`;
|
||||
});
|
||||
});
|
||||
|
||||
sitemap += '</urlset>';
|
||||
|
||||
return sitemap;
|
||||
}
|
||||
|
||||
fs.writeFileSync('build/sitemap.xml', generateSitemap());
|
||||
Reference in New Issue
Block a user