/* Index Manager This script handle adding and removing blog post from the index list. Use with include only. Call directly via AGI return nothing */ includes("helper.js"); function getIndexList(webroot){ webroot = filepathClean(webroot); var indexFile = webroot + "/blog/posts.json" if (!filelib.fileExists(indexFile)){ //Create it filelib.writeFile(indexFile, JSON.stringify([])); //Return an empty list return []; }else{ //Get the index file var content = filelib.readFile(indexFile); return JSON.parse(content); } } function writeIndexList(webroot, newListObject){ webroot = filepathClean(webroot); var indexFile = webroot + "/blog/posts.json" return filelib.writeFile(indexFile, JSON.stringify(newListObject)); } //This inject a new title into the post list function injectTitleIntoPostList(webroot, postObjectName){ var currentIndexList = getIndexList(webroot); if (currentIndexList.indexOf(postObjectName) > 0){ //Already exists in the list. No need to add it in }else{ //Push to the list currentIndexList.push(postObjectName); writeIndexList(webroot,currentIndexList); } } //This remove a post from the post list base on title function removeTitleFromPostList(webroot, postObjectName){ var currentIndexList = getIndexList(webroot); if (currentIndexList.indexOf(postObjectName) > 0){ //Already removed }else{ var newarray = []; for (var i = 0; i < currentIndexList.length; i++){ var thisIndex = currentIndexList[i]; if (thisIndex != postObjectName){ newarray.push(thisIndex); } } writeIndexList(webroot, newarray); } } //Get the current post in the system function getCurrentPostList(webroot, ){ }