Example #1
0
function createPost(postName) {
    util.mkdirIfNotExistsSync("posts");
    const postsPath = path.join( process.cwd(), "posts");
    const postFile = postName.replace(/\ /g,"-")+".md";
    const postPath = path.join(postsPath, postFile);

    let date = new Date();

    const content =
`{{{
    "date": "${date.toLocaleString()}",
    "tags": [],
    "title": "${postName}"
}}}

Write here with markdown!
`;
let hash = util.getHashOfData(content);
    try{
      fs.accessSync(postPath);
    }
    catch(error){
      fs.writeFileSync(postPath, content, "utf8");
      let list = util.getFileHashListFrom(".filechecksum");
      list[postFile] = hash;
      util.writeFileHashListTo(".filechecksum", list);
    }
    console.log(postPath);
    process.exit(0);
}
Example #2
0
function listPosts(){
  let postDirectory = path.join(process.cwd(), "posts");
  let postList = fs.readdirSync(postDirectory);
  let list = util.getFileHashListFrom(".filechecksum");
  postList.forEach((postName) => {
    let postPath = path.join(postDirectory, postName);
    let sum = util.getHashOfFile(postPath);
    let output = postName.replace(/-/g, "\ ");
    output += sum === list[postName] ? "" : "\tm"
    console.log(output);
  });
}