Просмотр исходного кода

Add PWA functionality by OpenCode

jerryliao 2 недель назад
Родитель
Сommit
65501ab622
6 измененных файлов с 887 добавлено и 4 удалено
  1. 1 0
      deno.json
  2. 834 3
      deno.lock
  3. 7 0
      routes/_app.tsx
  4. BIN
      static/icon-192.png
  5. BIN
      static/icon-512.png
  6. 45 1
      vite.config.ts

+ 1 - 0
deno.json

@@ -36,6 +36,7 @@
     "@fresh/plugin-vite": "jsr:@fresh/plugin-vite@^1.0.8",
     "usid": "npm:usid@^2.0.0",
     "vite": "npm:vite@^7.1.3",
+    "vite-plugin-pwa": "npm:vite-plugin-pwa@^1.0.1",
     "@tailwindcss/vite": "npm:@tailwindcss/vite@^4.2.2",
     "tailwindcss": "npm:tailwindcss@^4.2.2",
     "jsdom": "npm:jsdom@^26.0.0",

Разница между файлами не показана из-за своего большого размера
+ 834 - 3
deno.lock


+ 7 - 0
routes/_app.tsx

@@ -2,11 +2,17 @@ import type { PageProps } from "fresh";
 import { define } from "utils/state.ts";
 import Modal from "../islands/Modal.tsx";
 import Loading from "../islands/Loading.tsx";
+import StatusIndicator from "../islands/StatusIndicator.tsx";
 
 export default define.page(({ Component }: PageProps) => {
   return (
     <html>
       <head>
+        <meta name="theme-color" content="#1e293b" />
+        <meta name="apple-mobile-web-app-capable" content="yes" />
+        <meta name="apple-mobile-web-app-status-bar-style" content="default" />
+        <meta name="apple-mobile-web-app-title" content="Postdown" />
+        <link rel="apple-touch-icon" href="/icon-192.png" />
         <link
           href="https://unpkg.com/bootstrap-icons@1.10.4/font/bootstrap-icons.css"
           rel="stylesheet"
@@ -19,6 +25,7 @@ export default define.page(({ Component }: PageProps) => {
         />
       </head>
       <body className="bg-white dark:bg-gray-900 text-gray-800 dark:text-gray-100 transition-colors">
+        <StatusIndicator />
         <Modal />
         <Loading />
         <Component />

BIN
static/icon-192.png


BIN
static/icon-512.png


+ 45 - 1
vite.config.ts

@@ -1,9 +1,53 @@
 import { defineConfig } from "vite";
 import { fresh } from "@fresh/plugin-vite";
 import tailwindcss from "@tailwindcss/vite";
+import { VitePWA } from "vite-plugin-pwa";
 
 export default defineConfig({
-  plugins: [fresh(), tailwindcss()],
+  plugins: [
+    fresh(),
+    tailwindcss(),
+    VitePWA({
+      registerType: "autoUpdate",
+      manifest: {
+        name: "Postdown",
+        short_name: "Postdown",
+        description: "A web-based, shareable, self-hosted Markdown editor",
+        start_url: "/",
+        display: "standalone",
+        background_color: "#ffffff",
+        theme_color: "#1e293b",
+        orientation: "any",
+        icons: [
+          {
+            src: "/icon-192.png",
+            sizes: "192x192",
+            type: "image/png",
+          },
+          {
+            src: "/icon-512.png",
+            sizes: "512x512",
+            type: "image/png",
+          },
+        ],
+      },
+      workbox: {
+        navigateFallback: "/",
+        runtimeCaching: [
+          {
+            urlPattern: /^https?:\/\/.*\/.*/i,
+            handler: "NetworkFirst",
+            options: {
+              cacheName: "postdown-runtime",
+              expiration: {
+                maxEntries: 100,
+              },
+            },
+          },
+        ],
+      },
+    }),
+  ],
   server: {
     port: 8000,
     watch: {

Некоторые файлы не были показаны из-за большого количества измененных файлов