feat: add old browser check

Signed-off-by: Innei <i@innei.in>
This commit is contained in:
Innei
2024-11-11 00:35:20 +08:00
parent 9d0bc515ad
commit a4796ce4c9
5 changed files with 155 additions and 8 deletions
+1 -1
View File
@@ -14,7 +14,6 @@
<title>Follow</title>
<!-- Manifest -->
<link rel="manifest" href="/manifest.json" />
<meta property="og:type" content="website" />
<meta property="og:title" content="Follow" />
<meta property="og:url" content="https://app.follow.is" />
@@ -24,6 +23,7 @@
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:title" content="Follow" />
<meta name="twitter:image" content="https://app.follow.is/og-image.png" />
<!-- Check Browser Script Inject -->
<script>
function setTheme() {
+13 -3
View File
@@ -3,7 +3,7 @@ import path, { resolve } from "node:path"
import { env } from "@follow/shared/env"
import type { FastifyInstance, FastifyReply, FastifyRequest } from "fastify"
import type { Document } from "linkedom"
import { minify } from "html-minifier"
import { parseHTML } from "linkedom"
import { FetchError } from "ofetch"
import xss from "xss"
@@ -76,10 +76,20 @@ injectEnv({"VITE_API_URL":"${apiUrl}","VITE_EXTERNAL_API_URL":"${apiUrl}","VITE_
}
reply.type("text/html")
reply.send(document.toString())
reply.send(
minify(document.toString(), {
removeComments: true,
html5: true,
minifyJS: true,
minifyCSS: true,
removeTagWhitespace: true,
collapseWhitespace: true,
collapseBooleanAttributes: true,
collapseInlineTagWhitespace: true,
}),
)
})
}
export const globalRoute = isDev ? devHandler : prodHandler
async function safeInjectMetaToTemplate(
+2
View File
@@ -64,6 +64,7 @@
"@t3-oss/env-core": "^0.11.1",
"@tailwindcss/container-queries": "0.1.1",
"@tailwindcss/typography": "0.5.15",
"@types/html-minifier": "4.0.5",
"@types/lodash-es": "4.17.12",
"@types/node": "^22.8.7",
"@types/react": "^18.3.12",
@@ -85,6 +86,7 @@
"fake-indexeddb": "6.0.0",
"happy-dom": "15.8.0",
"hono": "4.6.8",
"html-minifier": "4.0.0",
"js-yaml": "4.1.0",
"lint-staged": "15.2.10",
"nbump": "2.0.7",
+103 -2
View File
@@ -107,6 +107,9 @@ importers:
'@tailwindcss/typography':
specifier: 0.5.15
version: 0.5.15(tailwindcss@3.4.14(ts-node@10.9.1(@types/node@22.8.7)(typescript@5.6.3)))
'@types/html-minifier':
specifier: 4.0.5
version: 4.0.5
'@types/lodash-es':
specifier: 4.17.12
version: 4.17.12
@@ -170,6 +173,9 @@ importers:
hono:
specifier: 4.6.8
version: 4.6.8(patch_hash=qptujxncoai6tukc4qaqsrqk24)
html-minifier:
specifier: 4.0.0
version: 4.0.0
js-yaml:
specifier: 4.1.0
version: 4.1.0
@@ -4431,6 +4437,9 @@ packages:
'@types/cacheable-request@6.0.3':
resolution: {integrity: sha512-IQ3EbTzGxIigb1I3qPZc1rWJnH0BmSKv5QYTalEwweFvyBDLSAe24zP0le/hyi7ecGfZVlIVAg4BZqb8WBwKqw==}
'@types/clean-css@4.2.11':
resolution: {integrity: sha512-Y8n81lQVTAfP2TOdtJJEsCoYl1AnOkqDqMvXb9/7pfgZZ7r8YrEyurrAvAoAjHOGXKRybay+5CsExqIH6liccw==}
'@types/connect@3.4.36':
resolution: {integrity: sha512-P63Zd/JUGq+PdrM1lv0Wv5SBYeA2+CORvbrXbngriYY0jzLUWfQMQQxOhjONEz/wlHOAxOdY7CY65rgQdTjq2w==}
@@ -4455,6 +4464,9 @@ packages:
'@types/hast@3.0.4':
resolution: {integrity: sha512-WPs+bbQw5aCj+x6laNGWLH3wviHtoCv/P3+otBhbOhJgG8qtpdAMlTCxLtsTWA7LH1Oh/bFCHsBn0TPS5m30EQ==}
'@types/html-minifier@4.0.5':
resolution: {integrity: sha512-LfE7f7MFd+YUfZnlBz8W43P4NgSObWiqyKapANsWCj63Aqeqli8/9gVsGP4CwC8jPpTTYlTopKCk9rJSuht/ew==}
'@types/http-cache-semantics@4.0.4':
resolution: {integrity: sha512-1m0bIFVc7eJWyve9S0RnuRgcQqF/Xd5QsUZAZeQFr1Q3/p9JWoQQEqmVy+DPTNpGXwhgIetAoYF8JSc33q29QA==}
@@ -4518,6 +4530,9 @@ packages:
'@types/react@18.3.12':
resolution: {integrity: sha512-D2wOSq/d6Agt28q7rSI3jhU7G6aiuzljDGZ2hTZHIkrTLUI+AF3WMeKkEZ9nN2fkBAlcktT6vcZjDFiIhMYEQw==}
'@types/relateurl@0.2.33':
resolution: {integrity: sha512-bTQCKsVbIdzLqZhLkF5fcJQreE4y1ro4DIyVrlDNSCJRRwHhB8Z+4zXXa8jN6eDvc2HbRsEYgbvrnGvi54EpSw==}
'@types/responselike@1.0.3':
resolution: {integrity: sha512-H/+L+UkTV33uf49PH5pCAUBVPNj2nDBXTN+qS1dOwyyg24l3CcicicCA7ca+HMvJBZcFgl5r8e+RR6elsb4Lyw==}
@@ -4530,6 +4545,9 @@ packages:
'@types/tar@6.1.13':
resolution: {integrity: sha512-IznnlmU5f4WcGTh2ltRu/Ijpmk8wiWXfF0VA4s+HPjHZgvFggk1YaIkbo5krX/zUCzWF8N/l4+W/LNxnvAJ8nw==}
'@types/uglify-js@3.17.5':
resolution: {integrity: sha512-TU+fZFBTBcXj/GpDpDaBmgWk/gn96kMZ+uocaFUlV2f8a6WdMzzI44QBCmGcCiYR0Y6ZlNRiyUyKKt5nl/lbzQ==}
'@types/unist@2.0.11':
resolution: {integrity: sha512-CmBKiL6NNo/OqgmMn95Fk9Whlp2mtvIv+KNpQKN2F4SjvrEesubTRWGYSg+BnWZOnlCaSTU1sMpsBOzgbYhnsA==}
@@ -5183,6 +5201,9 @@ packages:
resolution: {integrity: sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==}
engines: {node: '>=6'}
camel-case@3.0.0:
resolution: {integrity: sha512-+MbKztAYHXPr1jNTSKQF52VpcFjwY5RkR7fxksV8Doo4KAYc5Fl4UJRgthBbTmEx8C54DqahhbLJkDwjI3PI/w==}
camelcase-css@2.0.1:
resolution: {integrity: sha512-QOSvevhslijgYwRx6Rv7zKdMF8lbRmx+uQGx2+vDc+KI/eBnsy9kit5aj23AgGu3pa4t9AgwbnXWqS+iOY+2aA==}
engines: {node: '>= 6'}
@@ -5291,6 +5312,10 @@ packages:
class-variance-authority@0.7.0:
resolution: {integrity: sha512-jFI8IQw4hczaL4ALINxqLEXQbWcNjoSkloa4IaufXCJr6QawJyw7tuRysRsrE8w2p/4gGaxKIt/hX3qz/IbD1A==}
clean-css@4.2.4:
resolution: {integrity: sha512-EJUDT7nDVFDvaQgAo2G/PJvxmp1o/c6iXLbswsBbUFXi1Nr+AjA2cKmfbKDMjMvzEe75g3P6JkaDDAKk96A85A==}
engines: {node: '>= 4.0'}
clean-regexp@1.0.0:
resolution: {integrity: sha512-GfisEZEJvzKrmGWkvfhgzcz/BllN1USeqD2V6tg14OAOgaCD2Z/PUEuxnAZ/nPvmaHRG7a8y77p1T/IRQ4D1Hw==}
engines: {node: '>=4'}
@@ -7100,6 +7125,10 @@ packages:
hastscript@9.0.0:
resolution: {integrity: sha512-jzaLBGavEDKHrc5EfFImKN7nZKKBdSLIdGvCwDZ9TfzbF2ffXiov8CKE445L2Z1Ek2t/m4SKQ2j6Ipv7NyUolw==}
he@1.2.0:
resolution: {integrity: sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==}
hasBin: true
hermes-estree@0.20.1:
resolution: {integrity: sha512-SQpZK4BzR48kuOg0v4pb3EAGNclzIlqMj3Opu/mu7bbAoFw6oig6cEt/RAi0zTFW/iW6Iz9X9ggGuZTAZ/yZHg==}
@@ -7141,6 +7170,11 @@ packages:
html-escaper@3.0.3:
resolution: {integrity: sha512-RuMffC89BOWQoY0WKGpIhn5gX3iI54O6nRA0yC124NYVtzjmFWBIiFd8M0x+ZdX0P9R4lADg1mgP8C7PxGOWuQ==}
html-minifier@4.0.0:
resolution: {integrity: sha512-aoGxanpFPLg7MkIl/DDFYtb0iWz7jMFGqFhvEDZga6/4QTjneiD8I/NXL1x5aaoCp7FSIT6h/OhykDdPsbtMig==}
engines: {node: '>=6'}
hasBin: true
html-parse-stringify@3.0.1:
resolution: {integrity: sha512-KknJ50kTInJ7qIScF3jeaFRpMpE8/lfiTdzf/twXyPBLAGrLRTmkz3AdTnKeh40X8k9L2fdYwEp/42WGXIRGcg==}
@@ -7807,6 +7841,9 @@ packages:
resolution: {integrity: sha512-neJAj8GwF0e8EpycYIDFqEPcx9Qz4GUho20jWFR7YiFeXzF1YMLdxB36PypcTSPMA+4+LvgyMacYhlr18Zlymw==}
engines: {node: '>=18'}
lower-case@1.1.4:
resolution: {integrity: sha512-2Fgx1Ycm599x+WGpIYwJOvsjmXFzTSc34IwDWALRA/8AopUKAVPwfJ+h5+f85BCp0PWmmJcWzEpxOpoXycMpdA==}
lowercase-keys@2.0.0:
resolution: {integrity: sha512-tqNXrS78oMOE73NMxK4EMLQsQowWf8jKooH9g7xPavRT706R6bkQJ6DY2Te7QukaZsulxa30wQ7bk0pm4XiHmA==}
engines: {node: '>=8'}
@@ -8227,6 +8264,9 @@ packages:
nice-try@1.0.5:
resolution: {integrity: sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==}
no-case@2.3.2:
resolution: {integrity: sha512-rmTZ9kz+f3rCvK2TD1Ue/oZlns7OGoIWP4fc3llxxRXlOkHKoWPPWJOfFYpITabSow43QJbRIoHQXtt10VldyQ==}
node-abi@3.67.0:
resolution: {integrity: sha512-bLn/fU/ALVBE9wj+p4Y21ZJWYFjUXLXPi/IewyLZkx3ApxKDNBWCKdReeKOtD8dWpOdDCeMyLh6ZewzcLsG2Nw==}
engines: {node: '>=10'}
@@ -8455,6 +8495,9 @@ packages:
pako@1.0.11:
resolution: {integrity: sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==}
param-case@2.1.1:
resolution: {integrity: sha512-eQE845L6ot89sk2N8liD8HAuH4ca6Vvr7VWAWwt7+kvvG5aBcPmmphQ68JsEG2qa9n1TykS2DLeMt363AAH8/w==}
parent-module@1.0.1:
resolution: {integrity: sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==}
engines: {node: '>=6'}
@@ -9349,6 +9392,10 @@ packages:
rehype-stringify@10.0.1:
resolution: {integrity: sha512-k9ecfXHmIPuFVI61B9DeLPN0qFHfawM6RsuX48hoqlaKSF61RskNjSm1lI8PhBEM0MRdLxVVm4WmTqJQccH9mA==}
relateurl@0.2.7:
resolution: {integrity: sha512-G08Dxvm4iDN3MLM0EsP62EDV9IuhXPR6blNz6Utcp7zyV3tr4HVNINt6MpaRWbxoOHT3Q7YN2P+jaHX8vUbgog==}
engines: {node: '>= 0.10'}
remark-directive@3.0.0:
resolution: {integrity: sha512-l1UyWJ6Eg1VPU7Hm/9tt0zKtReJQNOA4+iDMAxTyZNWnJnFlbS/7zhiel/rogTLQ2vMYwDzSJa4BiVNqGlqIMA==}
@@ -10328,6 +10375,9 @@ packages:
peerDependencies:
browserslist: '>= 4.21.0'
upper-case@1.1.3:
resolution: {integrity: sha512-WRbjgmYzgXkCV7zNVpy5YgrHgbBv126rMALQQMrmzOVC4GM2waQ9x7xtm8VU+1yF2kWyPzI9zbZ48n4vSxwfSA==}
uri-js@4.4.1:
resolution: {integrity: sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==}
@@ -14833,6 +14883,11 @@ snapshots:
'@types/node': 22.8.7
'@types/responselike': 1.0.3
'@types/clean-css@4.2.11':
dependencies:
'@types/node': 22.8.7
source-map: 0.6.1
'@types/connect@3.4.36':
dependencies:
'@types/node': 22.8.7
@@ -14862,6 +14917,12 @@ snapshots:
dependencies:
'@types/unist': 3.0.3
'@types/html-minifier@4.0.5':
dependencies:
'@types/clean-css': 4.2.11
'@types/relateurl': 0.2.33
'@types/uglify-js': 3.17.5
'@types/http-cache-semantics@4.0.4': {}
'@types/json-schema@7.0.15': {}
@@ -14935,6 +14996,8 @@ snapshots:
'@types/prop-types': 15.7.13
csstype: 3.1.3
'@types/relateurl@0.2.33': {}
'@types/responselike@1.0.3':
dependencies:
'@types/node': 22.8.7
@@ -14948,6 +15011,10 @@ snapshots:
'@types/node': 22.8.7
minipass: 4.2.8
'@types/uglify-js@3.17.5':
dependencies:
source-map: 0.6.1
'@types/unist@2.0.11': {}
'@types/unist@3.0.3': {}
@@ -15878,6 +15945,11 @@ snapshots:
callsites@3.1.0: {}
camel-case@3.0.0:
dependencies:
no-case: 2.3.2
upper-case: 1.1.3
camelcase-css@2.0.1: {}
camelcase-keys@9.1.3:
@@ -16001,6 +16073,10 @@ snapshots:
dependencies:
clsx: 2.0.0
clean-css@4.2.4:
dependencies:
source-map: 0.6.1
clean-regexp@1.0.0:
dependencies:
escape-string-regexp: 1.0.5
@@ -18272,6 +18348,8 @@ snapshots:
property-information: 6.5.0
space-separated-tokens: 2.0.2
he@1.2.0: {}
hermes-estree@0.20.1: {}
hermes-parser@0.20.1:
@@ -18310,6 +18388,16 @@ snapshots:
html-escaper@3.0.3: {}
html-minifier@4.0.0:
dependencies:
camel-case: 3.0.0
clean-css: 4.2.4
commander: 2.20.3
he: 1.2.0
param-case: 2.1.1
relateurl: 0.2.7
uglify-js: 3.19.3
html-parse-stringify@3.0.1:
dependencies:
void-elements: 3.1.0
@@ -18950,6 +19038,8 @@ snapshots:
dependencies:
steno: 4.0.2
lower-case@1.1.4: {}
lowercase-keys@2.0.0: {}
lru-cache@10.4.3: {}
@@ -19629,6 +19719,10 @@ snapshots:
nice-try@1.0.5: {}
no-case@2.3.2:
dependencies:
lower-case: 1.1.4
node-abi@3.67.0:
dependencies:
semver: 7.6.3
@@ -19861,6 +19955,10 @@ snapshots:
pako@1.0.11: {}
param-case@2.1.1:
dependencies:
no-case: 2.3.2
parent-module@1.0.1:
dependencies:
callsites: 3.1.0
@@ -20751,6 +20849,8 @@ snapshots:
hast-util-to-html: 9.0.3
unified: 11.0.5
relateurl@0.2.7: {}
remark-directive@3.0.0:
dependencies:
'@types/mdast': 4.0.4
@@ -21657,8 +21757,7 @@ snapshots:
ufo@1.5.4: {}
uglify-js@3.19.3:
optional: true
uglify-js@3.19.3: {}
uhyphen@0.2.0: {}
@@ -21816,6 +21915,8 @@ snapshots:
escalade: 3.2.0
picocolors: 1.1.0
upper-case@1.1.3: {}
uri-js@4.4.1:
dependencies:
punycode: 2.3.1
+36 -2
View File
@@ -2,6 +2,7 @@ import { resolve } from "node:path"
import { fileURLToPath } from "node:url"
import legacy from "@vitejs/plugin-legacy"
import { minify as htmlMinify } from "html-minifier"
import { cyan, dim, green } from "kolorist"
import type { PluginOption, ViteDevServer } from "vite"
import { defineConfig, loadEnv } from "vite"
@@ -72,8 +73,6 @@ export default ({ mode }) => {
modernTargets: ">0.3%, last 2 versions, Firefox ESR, not dead",
modernPolyfills: [
// https://unpkg.com/browse/core-js@3.39.0/modules/
"es.array.find-last-index",
"es.array.find-last",
"es.promise.with-resolvers",
],
}),
@@ -149,6 +148,7 @@ export default ({ mode }) => {
createPlatformSpecificImportPlugin(false),
manifestPlugin(),
htmlPlugin(typedEnv),
],
define: {
@@ -157,3 +157,37 @@ export default ({ mode }) => {
},
})
}
function checkBrowserSupport() {
if (!("findLastIndex" in Array.prototype) || !("structuredClone" in window)) {
window.alert(
"Follow is not compatible with your browser because your browser version is too old. You can download and use the Follow app or continue using it with the latest browser.",
)
window.location.href = "https://follow.is/download"
}
}
const htmlPlugin: (env: any) => PluginOption = () => {
return {
name: "html-transform",
enforce: "post",
transformIndexHtml(html) {
return htmlMinify(
html.replace(
"<!-- Check Browser Script Inject -->",
`<script>${checkBrowserSupport.toString()}; checkBrowserSupport()</script>`,
),
{
removeComments: true,
html5: true,
minifyJS: true,
minifyCSS: true,
removeTagWhitespace: true,
collapseWhitespace: true,
collapseBooleanAttributes: true,
collapseInlineTagWhitespace: true,
},
)
},
}
}