Spaces:
Sleeping
Sleeping
| 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}`); | |
| } | |
| }); | |