Add PWA support

This commit is contained in:
2023-07-17 21:55:48 +08:00
parent 46acf2980a
commit 219796269e
9 changed files with 67 additions and 3 deletions

View File

@@ -36,7 +36,7 @@ export default function Index({ data }: PageProps<Props>) {
: null}
</Head>
<GlobalContext>
<Container i18n={i18n} />
<Container i18n={i18n} lang={data.lang} />
</GlobalContext>
</body>
);

47
routes/manifest.json.ts Normal file
View File

@@ -0,0 +1,47 @@
import { Handlers } from "$fresh/server.ts";
import { get_i18nmap, i18n_handle_request } from "../server/i18ns.ts";
import t, { i18n_map } from "../server/i18n.ts";
export const handler: Handlers = {
GET(req, _ctx) {
const i18n = i18n_handle_request(req);
if (typeof i18n === "string") {
const m = get_i18nmap(i18n);
i18n_map.value = m;
const base = `/?lang=${i18n}`;
const data = {
name: t("common.title"),
lang: i18n,
start_url: base,
display: "standalone",
icons: [
{
src: "/favicon.ico",
sizes: "64x64",
"type": "image/vnd.microsoft.icon",
},
{
src: "/logo.svg",
sizes: "any",
"type": "image/svg+xml",
},
],
scope: base,
shortcuts: [
{
name: t("task.add"),
url: `${base}#/task_manager/new`,
},
{
name: t("common.settings"),
url: `${base}#/settings`,
},
],
};
return new Response(JSON.stringify(data), {
headers: { "Content-Type": "application/manifest+json" },
});
}
return i18n;
},
};