helper.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. Helper Class
  3. This script handles basic stuffs
  4. */
  5. function filepathClean(webroot){
  6. if (webroot.substr(webroot.length -1, 1) == "/"){
  7. webroot = webroot.substr(0, webroot.length - 1);
  8. }
  9. return webroot;
  10. }
  11. //Generate a quick summary for post object
  12. function extractPostInfo(filepath){
  13. var content = filelib.readFile(filepath);
  14. var postObject = JSON.parse(content);
  15. var title = "Untitled";
  16. var content = "(This post has no content)";
  17. var tags = [];
  18. if (typeof postObject.Title != "undefined"){
  19. title = postObject.Title
  20. }
  21. if (typeof postObject.Content != "undefined"){
  22. content = postObject.Content;
  23. if (content.split(" ").length > 100){
  24. //Trim the content off if it is longer than 100 words
  25. var words = content.split(" ");
  26. var trimmedContent = "";
  27. for (var i = 0; i < 100; i++){
  28. trimmedContent = trimmedContent + words[i] + " ";
  29. }
  30. trimmedContent = trimmedContent + "..."
  31. content = trimmedContent;
  32. }else if (content.length > 300){
  33. //To handle lang with no space, like Cantonese
  34. var trimmedContent = content.substr(0, 300) + "..."
  35. content = trimmedContent;
  36. }
  37. }
  38. if (typeof postObject.Tags != "undefined"){
  39. tags = postObject.Tags
  40. }
  41. return [title, content, tags];
  42. }
  43. function loadFooter(){
  44. //WIP
  45. var footerTemplate = appdata.readFile("Blog/template/footer.html");
  46. if (footerTemplate == false){
  47. return "Powered by ArozOS Blog Engine";
  48. }else{
  49. return footerTemplate;
  50. }
  51. }
  52. function loadBlogInfo(){
  53. //WIP
  54. return ["My Blog", "An amazing blog written by me!"]
  55. }
  56. function retrunErrorObject(message){
  57. sendJSONResp(JSON.stringify({
  58. error: message
  59. }))
  60. }