Skip to content

Commit

Permalink
Added to script to go straight to views/markdown folder and copy any …
Browse files Browse the repository at this point in the history
…images in the folder to the public docs subdir as well
  • Loading branch information
TravisH18 committed Sep 18, 2024
1 parent b6702cb commit 4b3a148
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions md_to_pug.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,26 @@ const path = require('path');
const markdownToPug = require('markdown-to-pug');

function convertMdToPug() {
const viewsDir = './views';
const viewsDir = './views/markdown'; // path.join(__dirname, 'views', 'markdown')
fs.readdir(viewsDir, (err, files) => {
if (err) throw err;

// for all the files in the markdown subdir
files.forEach(file => {
// if markdown file
if (path.extname(file) === '.md') {
const filePath = path.join(viewsDir, file);
fs.readFile(filePath, 'utf8', (err, data) => {
if (err) throw err;


// add pug template to beginning of markdown data
const pugContent = [
'extends layout.pug',
'block content',
markdownToPug(data)
].join('\n');

// write new pug data to views dir, file has same name but we change the extension
fs.writeFile(
path.join(viewsDir, `${file.replace(/\.md$/, '')}.pug`),
pugContent,
Expand All @@ -28,7 +32,17 @@ function convertMdToPug() {
);
});
}
// else if we have images in the markdown folder move those to the public docs folder
if (path.extname(file) === '.png' ||path.extname(file) === '.jpg' || path.extname(file) === '.gif') {
fs.rename(
path.join(viewsDir, file),
path.join('./docs/public/', file),
err => {
if (err) throw err;
});
};
});

});
}

Expand Down

0 comments on commit 4b3a148

Please sign in to comment.