scripts/fontScript/index.js

23 lines
992 B
JavaScript
Raw Normal View History

2024-11-28 21:07:52 +01:00
(async () => {
2024-11-28 21:10:40 +01:00
const website = window.location.origin; // Get the current website's base URL (or switch to "https://website.tld/")
const pathToCss = "path/to/css"; // Replace with the relative path to the CSS file
const cssUrl = `${website}/${pathToCss}`; // Combine base URL and CSS path
2024-11-28 21:07:52 +01:00
try {
// Fetch the CSS file
const response = await fetch(cssUrl);
const cssText = await response.text();
// Use a regular expression to extract the font file path
2024-11-28 21:10:40 +01:00
const fontMatch = cssText.match(/url\(['"]?(.*?\.(otf|ttf|woff|woff2|eot))['"]?\)/);
2024-11-28 21:07:52 +01:00
if (fontMatch && fontMatch[1]) {
const resolvedFontPath = new URL(fontMatch[1], cssUrl).href; // Resolve relative path
console.log(`Found font URL: ${resolvedFontPath}`);
} else {
console.log('Font not found in the CSS file.');
}
} catch (error) {
console.error('Error fetching or parsing the CSS file:', error);
}
})();