index.html 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="apple-mobile-web-app-capable" content="yes" />
  6. <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1"/>
  7. <meta name="theme-color" content="#ff9224">
  8. <link rel="stylesheet" href="../script/tocas/tocas.css">
  9. <script src="../script/tocas/tocas.js"></script>
  10. <script src="../script/jquery.min.js"></script>
  11. <script src="../script/ao_module.js"></script>
  12. <link rel="manifest" crossorigin="use-credentials" href="manifest.json">
  13. <title>Blog</title>
  14. <style>
  15. body{
  16. background-color: white;
  17. }
  18. .postControls{
  19. position: absolute;
  20. top: 0.5em;
  21. right: 0.5em;
  22. }
  23. .blog.main{
  24. background-color: #ff9224;
  25. border: 1px solid #ff9224;
  26. color: white;
  27. }
  28. .blog.main:hover{
  29. background-color: #c7721c !important;
  30. border: 1px solid #c7721c !important;
  31. color: white !important;
  32. }
  33. .blog.green{
  34. background-color: #47d191;
  35. border: 1px solid #47d191;
  36. color: white;
  37. }
  38. .blog.green:hover{
  39. background-color: #38a170 !important;
  40. border: 1px solid #38a170 !important;
  41. color: white !important;
  42. }
  43. .blog.red{
  44. background-color: #ff3d3d;
  45. border: 1px solid #ff3d3d;
  46. color: white;
  47. }
  48. .blog.red:hover{
  49. background-color: #962d2d !important;
  50. border: 1px solid #962d2d !important;
  51. color: white !important;
  52. }
  53. .blog.blue{
  54. background-color: #4287f5;
  55. border: 1px solid #4287f5;
  56. color: white;
  57. }
  58. .blog.blue:hover{
  59. background-color: #336bc4 !important;
  60. border: 1px solid #336bc4 !important;
  61. color: white !important;
  62. }
  63. .topPad{
  64. margin-top: 4px;
  65. }
  66. </style>
  67. </head>
  68. <body>
  69. <br><br>
  70. <div class="ts container">
  71. <div>
  72. <h4><img class="ts mini spaced image" src="img/module_icon.png" style="margin-right: 12px;"> Blog Writer</h4>
  73. </div>
  74. <div class="ts divider"></div>
  75. <div class="ts stackable grid">
  76. <!-- Post container-->
  77. <div class="twelve wide column" id="postList">
  78. </div>
  79. <!-- Setting container-->
  80. <div class="four wide column">
  81. <div class="ts segment">
  82. <a class="ts fluid small button blog main" href="editor.html"><i class="add icon"></i> New Post</a>
  83. <button class="ts fluid small button blog green topPad"><i class="text file outline icon"></i> Update Post Renders</button>
  84. <div class="ts divider"></div>
  85. <button class="ts fluid basic small button blog" onclick="openBlog();"><i class="text file outline icon"></i> View Blog</button>
  86. <button class="ts fluid basic small button blog topPad" onclick="openWebRoot();"><i class="folder open icon"></i> Open www</button>
  87. <div class="ts divider"></div>
  88. <button class="ts fluid basic small button topPad" onclick="openBlogSettings();"><i class="home icon"></i> Blog Settings</button>
  89. <button class="ts fluid basic small button topPad" onclick="openPersonalPageTab();"><i class="setting icon"></i> Homepage Settings</button>
  90. </div>
  91. </div>
  92. </div>
  93. <br><br><br>
  94. </div>
  95. <script>
  96. var currentWebDeployRoot = "";
  97. //Get the current web root path
  98. getWebRoot(function(){
  99. //List all the post stored in the system
  100. listPost();
  101. });
  102. function openBlogSettings(){
  103. window.location.href = "setting.html";
  104. }
  105. function openPost(object){
  106. //Parse the file object following ArozOS file descriptor protocol
  107. var filepath = $(object).attr("filepath");
  108. var filename = filepath.split("/").pop();
  109. var file = [{
  110. filename: filename,
  111. filepath: filepath
  112. }]
  113. var fd = encodeURIComponent(JSON.stringify(file));
  114. window.location.href = "editor.html#" + fd;
  115. }
  116. function openWebRoot(){
  117. getWebRoot(function(webroot){
  118. if (webroot != ""){
  119. ao_module_openPath(webroot);
  120. }else{
  121. alert("Web Root not set. Please go to Homepage Settings to setup your webroot before using B Blog Writer.")
  122. }
  123. });
  124. }
  125. function publishPostButton(object){
  126. var filepath = $(object).attr("filepath");
  127. publishPost(filepath);
  128. }
  129. function hidePostButton(btn){
  130. var filepath = $(btn).attr('filepath');
  131. $(btn).addClass("loading");
  132. ao_module_agirun("Blog/backend/hidePost.js",{
  133. webroot: currentWebDeployRoot,
  134. filepath: filepath
  135. }, function(data){
  136. listPost();
  137. $(btn).removeClass("loading");
  138. }, function(){
  139. //failed return
  140. $(btn).removeClass("loading");
  141. })
  142. }
  143. function publishPost(filepath){
  144. ao_module_agirun("Blog/backend/publish.js", {
  145. filepath: filepath,
  146. webroot: currentWebDeployRoot
  147. }, function(data){
  148. console.log(data);
  149. listPost();
  150. })
  151. }
  152. function openBlog(){
  153. checkIfWebRootEnabled(function(data){
  154. if (data == true){
  155. //Get the username of the current session
  156. $.get("../system/desktop/user", function(userinfo){
  157. //Open the page in new tab
  158. window.open("../www/" + userinfo.Username + "/blog/");
  159. });
  160. }else{
  161. alert("Personal page not enabled");
  162. }
  163. })
  164. }
  165. function openPersonalPageTab(){
  166. ao_module_openSetting("Network", "Personal Page");
  167. }
  168. function checkIfWebRootEnabled(callback){
  169. $.get("../system/network/www/toggle", function(data){
  170. callback(data);
  171. });
  172. }
  173. function getWebRoot(callback = undefined){
  174. $.get("../system/network/www/webRoot", function(data){
  175. if (data == null || data == "" || data == undefined){
  176. callback("");
  177. return;
  178. }
  179. currentWebDeployRoot = data;
  180. if (callback != undefined){
  181. callback(data);
  182. }
  183. });
  184. }
  185. function listPost(){
  186. $("#postList").html(``);
  187. ao_module_agirun("Blog/backend/listPosts.js", {
  188. webroot: currentWebDeployRoot
  189. }, function(data){
  190. if (data.length == 0){
  191. //There is no post in the system
  192. $("#postList").html(`<div class="ts segment post">
  193. <h5 class="ts header">
  194. <div class="content">
  195. No Blog Posts
  196. <div class="sub header">Create your first post with the "New Post"</div>
  197. </div>
  198. </h5>
  199. </div>`);
  200. }else{
  201. //Render the post
  202. console.log(data);
  203. data.forEach(post => {
  204. //Generate the tag HTML
  205. var tags = post.tags;
  206. var tagHTML = [];
  207. tags.forEach(tag => {
  208. tagHTML.push(`<a class="section">${tag}</a>`);
  209. });
  210. tagHTML = tagHTML.join(`<div class="divider">,</div>`);
  211. //Post view permission indicator
  212. var postViewIcon = "";
  213. //Publish or hide post button
  214. var publicPostOnly = "";
  215. var privatePostOnly = "";
  216. if (post.view == "private"){
  217. postViewIcon = `<i class="hide icon"></i> Draft`;
  218. publicPostOnly = "display:none;"
  219. }else{
  220. postViewIcon = `<i class="unhide icon"></i> Published`;
  221. privatePostOnly = "display:none;"
  222. }
  223. $("#postList").append(`<div class="ts segment post">
  224. <div class="ts header">
  225. <a href="#" onclick="openPost(this);" filepath="${post.filepath}">${post.title} </a>
  226. <div class="sub header">
  227. <div>
  228. <span style="padding-right: 1em;">${postViewIcon}</span>
  229. <span style="padding-right: 1em;"><i class="calendar icon"></i> ${post.modtime}</span>
  230. <div class="ts breadcrumb">
  231. <div class="section">
  232. <i class="tag icon"></i>
  233. </div>
  234. ${tagHTML}
  235. </div>
  236. </div>
  237. </div>
  238. </div>
  239. ${stripHtml(post.content)}
  240. <div class="postControls">
  241. <button onclick="hidePostButton(this);" filepath="${post.filepath}" style="${publicPostOnly}" class="ts mini icon button blog red" title="Hide Post"><i class="hide icon"></i></button>
  242. <button onclick="publishPostButton(this);" filepath="${post.filepath}" style="${privatePostOnly}" class="ts mini icon button blog green" title="Publish Post"><i class="upload icon"></i></button>
  243. </div>
  244. </div>`)
  245. })
  246. }
  247. });
  248. function stripHtml(html){
  249. let tmp = document.createElement("DIV");
  250. tmp.innerHTML = html;
  251. var result = tmp.textContent || tmp.innerText || "";
  252. return result;
  253. }
  254. }
  255. </script>
  256. </body>
  257. </html>