issue with notch
This commit is contained in:
1
site/src/env.d.ts
vendored
1
site/src/env.d.ts
vendored
@@ -5,6 +5,7 @@ interface ImportMetaEnv {
|
||||
readonly PUBLIC_UMAMI_SCRIPT_URL?: string;
|
||||
readonly PUBLIC_UMAMI_WEBSITE_ID?: string;
|
||||
readonly PUBLIC_ENABLE_SW?: string;
|
||||
readonly PUBLIC_ASSET_VERSION?: string;
|
||||
}
|
||||
|
||||
interface ImportMeta {
|
||||
|
||||
@@ -13,6 +13,8 @@ const cfg = getPublicConfig();
|
||||
|
||||
const siteUrl = (cfg.siteUrl || "http://localhost:4321").replace(/\/$/, "");
|
||||
const canonicalUrl = `${siteUrl}${canonicalPath.startsWith("/") ? canonicalPath : `/${canonicalPath}`}`;
|
||||
|
||||
const assetSuffix = cfg.assetVersion ? `?v=${encodeURIComponent(cfg.assetVersion)}` : "";
|
||||
---
|
||||
|
||||
<!doctype html>
|
||||
@@ -48,7 +50,7 @@ const canonicalUrl = `${siteUrl}${canonicalPath.startsWith("/") ? canonicalPath
|
||||
rel="stylesheet"
|
||||
/>
|
||||
|
||||
<link rel="stylesheet" href="/styles/global.css" />
|
||||
<link rel="stylesheet" href={`/styles/global.css${assetSuffix}`} />
|
||||
|
||||
<script is:inline>
|
||||
(() => {
|
||||
@@ -117,12 +119,13 @@ const canonicalUrl = `${siteUrl}${canonicalPath.startsWith("/") ? canonicalPath
|
||||
// Register SW only in production builds (Astro sets import.meta.env.PROD at build time).
|
||||
// Allow opting out via PUBLIC_ENABLE_SW="false".
|
||||
import.meta.env.PROD && import.meta.env.PUBLIC_ENABLE_SW !== "false" ? (
|
||||
<script is:inline>
|
||||
<script is:inline define:vars={{ assetSuffix }}>
|
||||
if ("serviceWorker" in navigator) {
|
||||
// SW requires HTTPS (or localhost). In prod we expect HTTPS.
|
||||
window.addEventListener("load", () => {
|
||||
const swUrl = "/sw.js" + assetSuffix;
|
||||
navigator.serviceWorker
|
||||
.register("/sw.js", { scope: "/", updateViaCache: "none" })
|
||||
.register(swUrl, { scope: "/", updateViaCache: "none" })
|
||||
.catch((err) => {
|
||||
// Progressive enhancement; keep failures non-fatal.
|
||||
console.warn("Service worker registration failed", err);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
type PublicConfig = {
|
||||
siteUrl?: string;
|
||||
assetVersion?: string;
|
||||
umami?: {
|
||||
scriptUrl: string;
|
||||
websiteId: string;
|
||||
@@ -23,11 +24,13 @@ type IngestConfig = {
|
||||
|
||||
export function getPublicConfig(): PublicConfig {
|
||||
const siteUrl = import.meta.env.PUBLIC_SITE_URL;
|
||||
const assetVersion = import.meta.env.PUBLIC_ASSET_VERSION;
|
||||
const scriptUrl = import.meta.env.PUBLIC_UMAMI_SCRIPT_URL;
|
||||
const websiteId = import.meta.env.PUBLIC_UMAMI_WEBSITE_ID;
|
||||
|
||||
return {
|
||||
siteUrl,
|
||||
assetVersion,
|
||||
umami: scriptUrl && websiteId ? { scriptUrl, websiteId } : undefined,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user