function daysIntoYear(date){ return (Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()) - Date.UTC(date.getFullYear(), 0, 0)) / 24 / 60 / 60 / 1000; } function secondsIntoDay(time) { let hour = time.getUTCHours(); let minute = time.getUTCMinutes(); let second = time.getUTCSeconds(); return ((hour * 3600) + (minute * 60) + second) } const serverPath = require("./serverPath.js") const blogs = require(serverPath+"/blogs/blogs.js"); const filePath = serverPath+"/blog/"; const fs = require("fs"); const { pageTop, pageBottom } = require(serverPath+"/html.js") const comments = require(serverPath+"/blogs/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 date = new Date(blogs[length][2]) let second = Math.round((secondsIntoDay(date) / (86400/65536))).toString(16); let day = daysIntoYear(date).toString(16); let year = date.getUTCFullYear().toString(16); blogs[length][1] = blogs[length][1].replace(/(?:\r\n|\r|\n)/g, '
') blogs[length][1] = blogs[length][1].replace(/(?:\t)/g, '     ') let content = ` ${pageTop}

${second} ${day}/${year}

${blogs[length][0]}

${blogs[length][1]}

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

Comments section:



` for (let comment = 0; comment${comments[length][comment][0]}: ${comments[length][comment][1]}
` } content+=`
` 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 blogs[lastitem][1] = blogs[lastitem][1].replace(/(?:\r\n|\r|\n)/g, '
') blogs[lastitem][1] = blogs[lastitem][1].replace(/(?:\t)/g, '     ') 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]; blogs[length][1] = blogs[length][1].replace(/(?:\r\n|\r|\n)/g, '
') blogs[length][1] = blogs[length][1].replace(/(?:\t)/g, '     ') 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.'); } }); }