hidePost.js 959 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. Hide a published post from the blog engine
  3. Require paramter:
  4. filepath
  5. webroot
  6. */
  7. requirelib("filelib");
  8. requirelib("appdata");
  9. includes("config.js");
  10. includes("helper.js");
  11. includes("indexManager.js");
  12. function hidePost(postObjectName, webroot){
  13. //Check public post exists
  14. var publishWebPosition = filepathClean(webroot) + "/blog/posts/" + postObjectName + ".html";
  15. if (filelib.fileExists(publishWebPosition)){
  16. filelib.deleteFile(publishWebPosition);
  17. }
  18. //Remove the file from the index list
  19. removeTitleFromPostList(webroot, postObjectName);
  20. sendResp("OK");
  21. }
  22. function getPostNameFromFilepath(path){
  23. var tmp = path.split("/").pop();
  24. if (tmp.indexOf(".html") >= 0){
  25. tmp = tmp.replace(".html", "");
  26. }else if (tmp.indexOf(".json") >= 0){
  27. tmp = tmp.replace(".json", "");
  28. }
  29. return tmp;
  30. }
  31. var postName = getPostNameFromFilepath(filepath);
  32. hidePost(postName, webroot);