| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 | /*    ListPost.js    Author: tobychui    This script list all the post within the system    Require paramter:    webroot //The web deploy root of this user*///Require the file libraryrequirelib("filelib");//Require the internal library for handling the path of blog postingincludes("config.js");includes("helper.js");var blogPostStorage = getBlogPostStore();function main(){    //Filter out the last / if exists    blogPostStorage = filepathClean(blogPostStorage);    filelib.mkdir(blogPostStorage + "/posts/");    //List all the created post    var posts = filelib.aglob(blogPostStorage + "/posts/*.json","reverse");    var renderedPostList = [];    for(var i = 0; i < posts.length; i++){        //Extract post information        var postInfo = extractPostInfo( posts[i]);        //Get the poost modification time        var modTime = filelib.mtime(posts[i], false);        //Check if this post is published        webroot = filepathClean(webroot);        var postView = "private";        var postfilename = posts[i].split("/").pop().replace(".json", ".html");        if (filelib.fileExists(webroot + "/blog/posts/" + postfilename)){            postView = "public";        }        renderedPostList.push({            "title": postInfo[0],            "content":postInfo[1],            "tags": postInfo[2],            "modtime": modTime,            "view": postView,            "filepath": posts[i]        });    }    //Return the value of the posts    sendJSONResp(JSON.stringify(renderedPostList));}main();
 |