scripts/fontScript/index.js
2024-11-28 21:07:52 +01:00

23 lines
915 B
JavaScript

(async () => {
const website = "https://example.tld/"; // Replace with the URL of the website
const pathToCss = "path/to/css"; // Replace with the path to the CSS file
const cssUrl = website + pathToCss;
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
const fontMatch = cssText.match(/url\(['"]?(.*?web-font\.(otf|ttf|woff|woff2|eot))['"]?\)/);
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);
}
})();