PozoAppNov266pm/scripts/updateSEO.js

40 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

const fs = require('fs');
const path = require('path');
// Function to update index.html with dynamic SEO data
async function updateIndexHTML(seoData) {
const indexPath = path.join(__dirname, '../dist/index.html');
let html = fs.readFileSync(indexPath, 'utf8');
// Replace meta tags with dynamic data
html = html.replace(
/<meta name="description" content="[^"]*">/,
`<meta name="description" content="${seoData.metaDescription}">`
);
html = html.replace(
/<meta property="og:title" content="[^"]*">/,
`<meta property="og:title" content="${seoData.metaTitle}">`
);
html = html.replace(
/<meta property="og:description" content="[^"]*">/,
`<meta property="og:description" content="${seoData.metaDescription}">`
);
html = html.replace(
/<meta name="keywords" content="[^"]*">/,
`<meta name="keywords" content="${seoData.keywords}">`
);
html = html.replace(
/<title>[^<]*<\/title>/,
`<title>${seoData.metaTitle}</title>`
);
// Write updated HTML
fs.writeFileSync(indexPath, html);
console.log('SEO updated successfully!');
}
module.exports = { updateIndexHTML };