mirror of
https://github.com/bartvdbraak/hellob.art.git
synced 2025-04-26 17:11: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!
|
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:
|
Some dependencies may hold different licenses but are in compliance with GPLv3:
|
||||||
- `MIT`: Compatible with GPLv3.
|
|
||||||
- `Apache 2.0`: Compatible with GPLv3.
|
- `MIT`: Compatible with GPLv3.
|
||||||
- `BSD-3-Clause`: Compatible with GPLv3.
|
- `Apache 2.0`: Compatible with GPLv3.
|
||||||
- `BSD-2-Clause`: Compatible with GPLv3.
|
- `BSD-3-Clause`: Compatible with GPLv3.
|
||||||
- `ISC`: Compatible with GPLv3.
|
- `BSD-2-Clause`: Compatible with GPLv3.
|
||||||
- `Python-2.0`: Compatible with GPLv3. (Note: Python has its own license, and version 2.0 is compatible with GPLv3).
|
- `ISC`: 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.
|
- `Python-2.0`: Compatible with GPLv3. (Note: Python has its own license, and version 2.0 is compatible with GPLv3).
|
||||||
- `CC0-1.0`: Not a software license, but it is explicitly designed to waive all copyrights, making it effectively 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.
|
||||||
- `0BSD`: Compatible with GPLv3.
|
- `CC0-1.0`: Not a software license, but it is explicitly designed to waive all copyrights, making it effectively compatible with GPLv3.
|
||||||
- `(MIT OR CC0-1.0)`: MIT is compatible with GPLv3, and CC0-1.0 is 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
|
// Improve type safety by defining the navigator.connection type
|
||||||
interface NavigatorWithConnection extends Navigator {
|
interface NavigatorWithConnection extends Navigator {
|
||||||
connection: {
|
connection: {
|
||||||
effectiveType: string;
|
effectiveType: string;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
type Params = Record<string, any>; // Define a type for 'params'
|
type Params = Record<string, any>; // Define a type for 'params'
|
||||||
|
|
||||||
function getConnectionSpeed() {
|
function getConnectionSpeed() {
|
||||||
return 'connection' in navigator && 'connection' && 'effectiveType' in (navigator as NavigatorWithConnection).connection
|
return 'connection' in navigator &&
|
||||||
? (navigator as NavigatorWithConnection).connection.effectiveType
|
'connection' &&
|
||||||
: '';
|
'effectiveType' in (navigator as NavigatorWithConnection).connection
|
||||||
|
? (navigator as NavigatorWithConnection).connection.effectiveType
|
||||||
|
: '';
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendToAnalytics(metric: Metric, options: {
|
function sendToAnalytics(
|
||||||
params: Params;
|
metric: Metric,
|
||||||
path: string;
|
options: {
|
||||||
analyticsId: string;
|
params: Params;
|
||||||
debug: boolean;
|
path: string;
|
||||||
}) {
|
analyticsId: string;
|
||||||
const page = Object.entries(options.params).reduce(
|
debug: boolean;
|
||||||
(acc, [key, value]) => acc.replace(value, `[${key}]`),
|
}
|
||||||
options.path
|
) {
|
||||||
);
|
const page = Object.entries(options.params).reduce(
|
||||||
|
(acc, [key, value]) => acc.replace(value, `[${key}]`),
|
||||||
|
options.path
|
||||||
|
);
|
||||||
|
|
||||||
const body = {
|
const body = {
|
||||||
dsn: options.analyticsId,
|
dsn: options.analyticsId,
|
||||||
id: metric.id,
|
id: metric.id,
|
||||||
page,
|
page,
|
||||||
href: location.href,
|
href: location.href,
|
||||||
event_name: metric.name,
|
event_name: metric.name,
|
||||||
value: metric.value.toString(),
|
value: metric.value.toString(),
|
||||||
speed: getConnectionSpeed(),
|
speed: getConnectionSpeed()
|
||||||
};
|
};
|
||||||
|
|
||||||
if (options.debug) {
|
if (options.debug) {
|
||||||
console.log('[Web Vitals]', metric.name, JSON.stringify(body, null, 2));
|
console.log('[Web Vitals]', metric.name, JSON.stringify(body, null, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Serialize body to a URLSearchParams object
|
// Serialize body to a URLSearchParams object
|
||||||
const searchParams = new URLSearchParams(body);
|
const searchParams = new URLSearchParams(body);
|
||||||
|
|
||||||
// The type 'Record<string, string>' is compatible with 'URLSearchParams'
|
// The type 'Record<string, string>' is compatible with 'URLSearchParams'
|
||||||
const blob = new Blob([searchParams.toString()], {
|
const blob = new Blob([searchParams.toString()], {
|
||||||
type: 'application/x-www-form-urlencoded',
|
type: 'application/x-www-form-urlencoded'
|
||||||
});
|
});
|
||||||
if (navigator.sendBeacon) {
|
if (navigator.sendBeacon) {
|
||||||
navigator.sendBeacon(vitalsUrl, blob);
|
navigator.sendBeacon(vitalsUrl, blob);
|
||||||
} else {
|
} else {
|
||||||
fetch(vitalsUrl, {
|
fetch(vitalsUrl, {
|
||||||
body: blob,
|
body: blob,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
credentials: 'omit',
|
credentials: 'omit',
|
||||||
keepalive: true,
|
keepalive: true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function webVitals(options: {
|
export function webVitals(options: {
|
||||||
params: Params; // Use the defined 'Params' type here
|
params: Params; // Use the defined 'Params' type here
|
||||||
path: string;
|
path: string;
|
||||||
analyticsId: string;
|
analyticsId: string;
|
||||||
debug: boolean;
|
debug: boolean;
|
||||||
}) {
|
}) {
|
||||||
try {
|
try {
|
||||||
getFID((metric) => sendToAnalytics(metric, options));
|
getFID((metric) => sendToAnalytics(metric, options));
|
||||||
getTTFB((metric) => sendToAnalytics(metric, options));
|
getTTFB((metric) => sendToAnalytics(metric, options));
|
||||||
getLCP((metric) => sendToAnalytics(metric, options));
|
getLCP((metric) => sendToAnalytics(metric, options));
|
||||||
getCLS((metric) => sendToAnalytics(metric, options));
|
getCLS((metric) => sendToAnalytics(metric, options));
|
||||||
getFCP((metric) => sendToAnalytics(metric, options));
|
getFCP((metric) => sendToAnalytics(metric, options));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('[Web Vitals]', err);
|
console.error('[Web Vitals]', err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,10 +3,10 @@ import { defineConfig } from 'vite';
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [sveltekit()],
|
plugins: [sveltekit()],
|
||||||
ssr: {
|
ssr: {
|
||||||
noExternal: ['three']
|
noExternal: ['three']
|
||||||
},
|
},
|
||||||
define: {
|
define: {
|
||||||
'import.meta.env.VERCEL_ANALYTICS_ID': JSON.stringify(process.env.VERCEL_ANALYTICS_ID)
|
'import.meta.env.VERCEL_ANALYTICS_ID': JSON.stringify(process.env.VERCEL_ANALYTICS_ID)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue