Spaces:
Sleeping
Sleeping
File size: 1,264 Bytes
7b3aac2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | const fs = require('fs');
const path = require('path');
const dir = __dirname;
const files = fs.readdirSync(dir).filter(f => f.endsWith('.html'));
const headInject = `\n <!-- AOS CSS -->\n <link href="https://unpkg.com/aos@2.3.1/dist/aos.css" rel="stylesheet">`;
const bodyInject = `\n <!-- Global Preloader -->\n <div id="global-preloader" class="preloader">\n <div class="preloader-spinner"></div>\n </div>`;
const scriptInject = `\n <!-- AOS JS -->\n <script src="https://unpkg.com/aos@2.3.1/dist/aos.js"></script>\n`;
files.forEach(file => {
let content = fs.readFileSync(path.join(dir, file), 'utf8');
let changed = false;
if (!content.includes('aos.css')) {
content = content.replace('</head>', headInject + '\n</head>');
changed = true;
}
if (!content.includes('global-preloader')) {
content = content.replace(/<body[^>]*>/, match => match + bodyInject);
changed = true;
}
if (!content.includes('aos.js')) {
content = content.replace('</body>', scriptInject + '</body>');
changed = true;
}
if (changed) {
fs.writeFileSync(path.join(dir, file), content, 'utf8');
console.log(`Injected into ${file}`);
}
});
|