const fs = require('fs'); const path = require('path'); // Define metadata for routes const staticMeta = { '/': { title: 'itzMiney\'s Home', description: 'Welcome to itzMiney\'s Homepage! Here you can find my portfolio and other cool stuff.', image: 'https://meta.itzminey.dev/assets/ogimg.png', url: 'https://itzminey.dev/about', color: '#0095a4' }, '/about': { title: 'itzMiney\'s Home', description: 'Welcome to itzMiney\'s Homepage! Here you can find my portfolio and other cool stuff.', image: 'https://meta.itzminey.dev/assets/ogimg.png', url: 'https://itzminey.dev/about', color: '#0095a4' }, '/portfolio': { title: 'Portfolio | itzMiney', description: 'This is my portfolio where you can find examples of my designs and other projects!', image: 'https://meta.itzminey.dev/assets/ogimg.png', url: 'https://itzminey.dev/portfolio', color: '#0095a4' }, '/socials': { title: 'Socials | itzMiney', description: 'Here you can find links to all the places I hang around in!', image: 'https://meta.itzminey.dev/assets/ogimg.png', url: 'https://itzminey.dev/socials', color: '#0095a4' }, '/blog': { title: 'Blog | itzMiney', description: 'Welcome to my blog! I\'ll post occasional updates here on the stuff I\'m currently up to.', image: 'https://meta.itzminey.dev/assets/ogimg.png', url: 'https://itzminey.dev/blog', color: '#0095a4' }, '/login': { title: 'Login | itzMiney', description: 'Admin Panel Login', image: 'https://meta.itzminey.dev/assets/ogimg.png', url: 'https://itzminey.dev/login', color: '#0095a4' }, '/admin': { title: 'Admin Panel | itzMiney', description: 'Admin Panel', image: 'https://meta.itzminey.dev/assets/ogimg.png', url: 'https://itzminey.dev/admin', color: '#0095a4' }, '/404': { title: '404 | Page Not Found', description: 'How the hell did you end up here?', image: 'https://meta.itzminey.dev/assets/ogimg.png', url: 'https://itzminey.dev/404', color: '#0095a4', }, '/privacy': { title: 'Privacy Policy | itzMiney', description: 'My Privacy Policy for the data collected on this site', image: 'https://meta.itzminey.dev/assets/ogimg.png', url: 'https://itzminey.dev/tos', color: '#0095a4' }, '/imprint': { title: 'Imprint | itzMiney', description: 'Imprint and Contact', image: 'https://meta.itzminey.dev/assets/ogimg.png', url: 'https://itzminey.dev/imprint', color: '#0095a4' } }; // Output directory for pre-rendered metadata const outputDir = path.join(__dirname, '../dist/itzmineydev/meta'); // Ensure the output directory exists fs.mkdirSync(outputDir, { recursive: true }); function ensureFolderExists(folderPath) { if (!fs.existsSync(folderPath)) { fs.mkdirSync(folderPath, { recursive: true }); } } // Function to generate metadata files async function generateMetaFiles() { Object.entries(staticMeta).forEach(([route, meta]) => { const routePath = route === '/' ? 'index.html' : 'index.html'; const folderPath = path.join(outputDir, route === '/' ? '' : route.replace(/\//g, '/')); const filePath = path.join(folderPath, routePath); // Ensure the folder path exists ensureFolderExists(folderPath); // Generate metadata content const metaTags = ` ${meta.title} `; // Write the metadata to the file fs.writeFileSync(filePath, metaTags.trim()); console.log(`Generated metadata for ${route}: ${filePath}`); }); } function copyFolderRecursiveSync(source, target) { if (!fs.existsSync(source)) { console.warn(`Source folder "${source}" does not exist.`); return; } const files = fs.readdirSync(source); // Ensure the target directory exists fs.mkdirSync(target, { recursive: true }); for (const file of files) { const currentSource = path.join(source, file); const currentTarget = path.join(target, file); if (fs.lstatSync(currentSource).isDirectory()) { copyFolderRecursiveSync(currentSource, currentTarget); // Recurse } else { fs.copyFileSync(currentSource, currentTarget); } } } generateMetaFiles().then(); console.log('Metadata generation complete!') const sourceAssets = path.join(__dirname, '../public/assets'); const targetAssets = path.join(outputDir, 'assets'); copyFolderRecursiveSync(sourceAssets, targetAssets); console.log(`Copied assets to ${targetAssets}`);