mirror of
https://github.com/bartvdbraak/hellob.art.git
synced 2025-04-26 09:01:21 +00:00
refactor: prettier format fixes
This commit is contained in:
parent
95d99e0970
commit
5b6289b665
3 changed files with 79 additions and 73 deletions
21
README.md
21
README.md
|
@ -58,13 +58,14 @@ I'm open to contributions! If you find any bugs, have suggestions, or want to ad
|
|||
This project is licensed under the GPLv3 License. Feel free to explore, learn, and have fun!
|
||||
|
||||
Some dependencies may hold different licenses but are in compliance with GPLv3:
|
||||
- `MIT`: Compatible with GPLv3.
|
||||
- `Apache 2.0`: Compatible with GPLv3.
|
||||
- `BSD-3-Clause`: Compatible with GPLv3.
|
||||
- `BSD-2-Clause`: Compatible with GPLv3.
|
||||
- `ISC`: Compatible with GPLv3.
|
||||
- `Python-2.0`: Compatible with GPLv3. (Note: Python has its own license, and version 2.0 is compatible with GPLv3).
|
||||
- `CC-BY-4.0`: This is a Creative Commons license, which is not a software license. It's generally not recommended to include CC licenses in software projects due to potential compatibility issues. This might cause complications if you choose GPLv3.
|
||||
- `CC0-1.0`: Not a software license, but it is explicitly designed to waive all copyrights, making it effectively compatible with GPLv3.
|
||||
- `0BSD`: Compatible with GPLv3.
|
||||
- `(MIT OR CC0-1.0)`: MIT is compatible with GPLv3, and CC0-1.0 is effectively compatible with GPLv3.
|
||||
|
||||
- `MIT`: Compatible with GPLv3.
|
||||
- `Apache 2.0`: Compatible with GPLv3.
|
||||
- `BSD-3-Clause`: Compatible with GPLv3.
|
||||
- `BSD-2-Clause`: Compatible with GPLv3.
|
||||
- `ISC`: Compatible with GPLv3.
|
||||
- `Python-2.0`: Compatible with GPLv3. (Note: Python has its own license, and version 2.0 is compatible with GPLv3).
|
||||
- `CC-BY-4.0`: This is a Creative Commons license, which is not a software license. It's generally not recommended to include CC licenses in software projects due to potential compatibility issues. This might cause complications if you choose GPLv3.
|
||||
- `CC0-1.0`: Not a software license, but it is explicitly designed to waive all copyrights, making it effectively compatible with GPLv3.
|
||||
- `0BSD`: Compatible with GPLv3.
|
||||
- `(MIT OR CC0-1.0)`: MIT is compatible with GPLv3, and CC0-1.0 is effectively compatible with GPLv3.
|
||||
|
|
|
@ -5,77 +5,82 @@ const vitalsUrl = 'https://vitals.vercel-analytics.com/v1/vitals';
|
|||
|
||||
// Improve type safety by defining the navigator.connection type
|
||||
interface NavigatorWithConnection extends Navigator {
|
||||
connection: {
|
||||
effectiveType: string;
|
||||
};
|
||||
connection: {
|
||||
effectiveType: string;
|
||||
};
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
type Params = Record<string, any>; // Define a type for 'params'
|
||||
|
||||
function getConnectionSpeed() {
|
||||
return 'connection' in navigator && 'connection' && 'effectiveType' in (navigator as NavigatorWithConnection).connection
|
||||
? (navigator as NavigatorWithConnection).connection.effectiveType
|
||||
: '';
|
||||
return 'connection' in navigator &&
|
||||
'connection' &&
|
||||
'effectiveType' in (navigator as NavigatorWithConnection).connection
|
||||
? (navigator as NavigatorWithConnection).connection.effectiveType
|
||||
: '';
|
||||
}
|
||||
|
||||
function sendToAnalytics(metric: Metric, options: {
|
||||
params: Params;
|
||||
path: string;
|
||||
analyticsId: string;
|
||||
debug: boolean;
|
||||
}) {
|
||||
const page = Object.entries(options.params).reduce(
|
||||
(acc, [key, value]) => acc.replace(value, `[${key}]`),
|
||||
options.path
|
||||
);
|
||||
function sendToAnalytics(
|
||||
metric: Metric,
|
||||
options: {
|
||||
params: Params;
|
||||
path: string;
|
||||
analyticsId: string;
|
||||
debug: boolean;
|
||||
}
|
||||
) {
|
||||
const page = Object.entries(options.params).reduce(
|
||||
(acc, [key, value]) => acc.replace(value, `[${key}]`),
|
||||
options.path
|
||||
);
|
||||
|
||||
const body = {
|
||||
dsn: options.analyticsId,
|
||||
id: metric.id,
|
||||
page,
|
||||
href: location.href,
|
||||
event_name: metric.name,
|
||||
value: metric.value.toString(),
|
||||
speed: getConnectionSpeed(),
|
||||
};
|
||||
const body = {
|
||||
dsn: options.analyticsId,
|
||||
id: metric.id,
|
||||
page,
|
||||
href: location.href,
|
||||
event_name: metric.name,
|
||||
value: metric.value.toString(),
|
||||
speed: getConnectionSpeed()
|
||||
};
|
||||
|
||||
if (options.debug) {
|
||||
console.log('[Web Vitals]', metric.name, JSON.stringify(body, null, 2));
|
||||
}
|
||||
if (options.debug) {
|
||||
console.log('[Web Vitals]', metric.name, JSON.stringify(body, null, 2));
|
||||
}
|
||||
|
||||
// Serialize body to a URLSearchParams object
|
||||
const searchParams = new URLSearchParams(body);
|
||||
// Serialize body to a URLSearchParams object
|
||||
const searchParams = new URLSearchParams(body);
|
||||
|
||||
// The type 'Record<string, string>' is compatible with 'URLSearchParams'
|
||||
const blob = new Blob([searchParams.toString()], {
|
||||
type: 'application/x-www-form-urlencoded',
|
||||
});
|
||||
if (navigator.sendBeacon) {
|
||||
navigator.sendBeacon(vitalsUrl, blob);
|
||||
} else {
|
||||
fetch(vitalsUrl, {
|
||||
body: blob,
|
||||
method: 'POST',
|
||||
credentials: 'omit',
|
||||
keepalive: true,
|
||||
});
|
||||
}
|
||||
// The type 'Record<string, string>' is compatible with 'URLSearchParams'
|
||||
const blob = new Blob([searchParams.toString()], {
|
||||
type: 'application/x-www-form-urlencoded'
|
||||
});
|
||||
if (navigator.sendBeacon) {
|
||||
navigator.sendBeacon(vitalsUrl, blob);
|
||||
} else {
|
||||
fetch(vitalsUrl, {
|
||||
body: blob,
|
||||
method: 'POST',
|
||||
credentials: 'omit',
|
||||
keepalive: true
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export function webVitals(options: {
|
||||
params: Params; // Use the defined 'Params' type here
|
||||
path: string;
|
||||
analyticsId: string;
|
||||
debug: boolean;
|
||||
params: Params; // Use the defined 'Params' type here
|
||||
path: string;
|
||||
analyticsId: string;
|
||||
debug: boolean;
|
||||
}) {
|
||||
try {
|
||||
getFID((metric) => sendToAnalytics(metric, options));
|
||||
getTTFB((metric) => sendToAnalytics(metric, options));
|
||||
getLCP((metric) => sendToAnalytics(metric, options));
|
||||
getCLS((metric) => sendToAnalytics(metric, options));
|
||||
getFCP((metric) => sendToAnalytics(metric, options));
|
||||
} catch (err) {
|
||||
console.error('[Web Vitals]', err);
|
||||
}
|
||||
try {
|
||||
getFID((metric) => sendToAnalytics(metric, options));
|
||||
getTTFB((metric) => sendToAnalytics(metric, options));
|
||||
getLCP((metric) => sendToAnalytics(metric, options));
|
||||
getCLS((metric) => sendToAnalytics(metric, options));
|
||||
getFCP((metric) => sendToAnalytics(metric, options));
|
||||
} catch (err) {
|
||||
console.error('[Web Vitals]', err);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,10 +3,10 @@ import { defineConfig } from 'vite';
|
|||
|
||||
export default defineConfig({
|
||||
plugins: [sveltekit()],
|
||||
ssr: {
|
||||
noExternal: ['three']
|
||||
},
|
||||
define: {
|
||||
'import.meta.env.VERCEL_ANALYTICS_ID': JSON.stringify(process.env.VERCEL_ANALYTICS_ID)
|
||||
}
|
||||
ssr: {
|
||||
noExternal: ['three']
|
||||
},
|
||||
define: {
|
||||
'import.meta.env.VERCEL_ANALYTICS_ID': JSON.stringify(process.env.VERCEL_ANALYTICS_ID)
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue