const blogs = require("/var/www/html/blog/blogs.js"); const filePath = "/var/www/html/blog/blogs/"; const fs = require("fs"); const { pageTop, pageBottom } = require("/var/www/html/html.js") const comments = require("/var/www/html/blog/comments.js") console.log(blogs); //////////////////////////////// // Make each individual blog page ///////////////////////////////// for (let length = 0; length < blogs.length; length++) { console.log(length) const blogFilePath = filePath + length + ".html"; let commentsHTML = "" for (let commentsCounter = comments[length].length - 1; commentsCounter >= 0; commentsCounter--) { commentsHTML += comments[length][commentsCounter] + "
" } let content = `${pageTop}

${blogs[length][2]}

${blogs[length][0]}

${blogs[length][1]}

${blogs[length][3] ? `
${blogs[length][3].map(image => `${image}`).join('')}
` : ''}
${blogs[length][4]}
${commentsHTML}
` if (length > 0) { // Generate link to previous blog content+=`

<-- Previous

` } if (length != blogs.length - 1) { // Generate link to next blog content+=`

Next -->

` } content += ` ${pageBottom}` fs.writeFile(blogFilePath, content, (err) => { if (err) { console.error('Error creating file:', err); } else { console.log('File created successfully:', blogFilePath); } }); /////////////////////// // Make latest blog ////////////////////// latestBlogPath = filePath + "latest.html" console.log(latestBlogPath) lastitem = blogs.length - 1 let latestcontent = `${pageTop}

${blogs[lastitem][2]}

${blogs[lastitem][0]}

${blogs[lastitem][1]}

${blogs[lastitem][3] ? `
${blogs[lastitem][3].map(image => `${image}`).join('')}
` : ''}
${blogs[lastitem][4]}

<-- Previous

${pageBottom}` fs.writeFile(latestBlogPath, latestcontent, (err) => { if (err) { console.error('Error creating file:', err); } else { console.log('File created successfully:', latestBlogPath); } }); /////////////////////// // Make entire blog ////////////////////// function entireBlogPost() { let htmlPage = pageTop; // Add each blog post to the HTML page for (let length = blogs.length - 1; length >= 0; length--) { const title = blogs[length][0]; const content = blogs[length][1]; const date = blogs[length][2]; htmlPage += `

${date}

${title}

${content}

${blogs[length][3] ? `
${blogs[length][3].map(image => `${image}`).join('')}
` : ''}
`; } //Remove the last
htmlPage = htmlPage.slice(0, -5) // Close the HTML page htmlPage += pageBottom; return htmlPage; } entireBlog = entireBlogPost() entireFeedPath = filePath + "all.html" fs.writeFile(entireFeedPath, entireBlog, (err) => { if (err) { console.error('Error writing to the file:', err); } else { console.log('Data has been written to the file successfully.'); } }); }