Skip to content

Commit

Permalink
Save
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-zakaria committed Dec 22, 2024
1 parent 7372639 commit 2e5ce85
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions logFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,34 @@ import path from 'path';

const directoryPath = path.join(process.cwd(), 'public/posts');

fs.readdir(directoryPath, (err, files) => {
fs.readdir(directoryPath, (err, fileNames) => {
if (err) {
return console.error('Unable to scan directory: ' + err);
}
// make renderedPosts folder if it doesn't exist
if (!fs.existsSync('public/renderedPosts')) {
fs.mkdirSync('public/renderedPosts');
}
console.log('Listing files in public/posts:');
files.forEach(file => {
fileNames.forEach(fileName => {
/*
For each file, create a new html file with the file name as the title
in public/renderedPosts
*/
// get filename without extension
const baseName = fileName.split('.')[0];
const html = `
<!DOCTYPE html>
<html>
<head>
<title>${file}</title>
<title>${baseName}</title>
</head>
<body>
<h1>${file}</h1>
<h1>${baseName}</h1>
</body>
</html>
`;
fs.writeFileSync(`public/renderedPosts/${file}.html`, html);
console.log(file);
fs.writeFileSync(`public/renderedPosts/${fileName}.html`, html);
console.log(fileName);
});
});

0 comments on commit 2e5ce85

Please sign in to comment.