index.html 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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 small button blog" onclick="openBlog();"><i class="text file outline icon"></i> View Blog</button>
  86. <button class="ts fluid small button blog topPad" onclick="openWebRoot();"><i class="folder open icon"></i> Open www</button>
  87. <button class="ts fluid small button topPad" onclick="openPersonalPageTab();"><i class="setting icon"></i> Homepage Settings</button>
  88. </div>
  89. </div>
  90. </div>
  91. <br><br><br>
  92. </div>
  93. <script>
  94. var currentWebDeployRoot = "";
  95. //Get the current web root path
  96. getWebRoot(function(){
  97. //List all the post stored in the system
  98. listPost();
  99. });
  100. function openPost(object){
  101. //Parse the file object following ArozOS file descriptor protocol
  102. var filepath = $(object).attr("filepath");
  103. var filename = filepath.split("/").pop();
  104. var file = [{
  105. filename: filename,
  106. filepath: filepath
  107. }]
  108. var fd = encodeURIComponent(JSON.stringify(file));
  109. window.location.href = "editor.html#" + fd;
  110. }
  111. function openWebRoot(){
  112. getWebRoot(function(webroot){
  113. if (webroot != ""){
  114. ao_module_openPath(webroot);
  115. }else{
  116. alert("Web Root not set. Please go to Homepage Settings to setup your webroot before using B Blog Writer.")
  117. }
  118. });
  119. }
  120. function publishPostButton(object){
  121. var filepath = $(object).attr("filepath");
  122. publishPost(filepath);
  123. }
  124. function hidePostButton(btn){
  125. var filepath = $(btn).attr('filepath');
  126. $(btn).addClass("loading");
  127. ao_module_agirun("Blog/backend/hidePost.js",{
  128. webroot: currentWebDeployRoot,
  129. filepath: filepath
  130. }, function(data){
  131. listPost();
  132. $(btn).removeClass("loading");
  133. }, function(){
  134. //failed return
  135. $(btn).removeClass("loading");
  136. })
  137. }
  138. function publishPost(filepath){
  139. ao_module_agirun("Blog/backend/publish.js", {
  140. filepath: filepath,
  141. webroot: currentWebDeployRoot
  142. }, function(data){
  143. console.log(data);
  144. listPost();
  145. })
  146. }
  147. function openBlog(){
  148. checkIfWebRootEnabled(function(data){
  149. if (data == true){
  150. //Get the username of the current session
  151. $.get("../system/desktop/user", function(userinfo){
  152. //Open the page in new tab
  153. window.open("../www/" + userinfo.Username + "/blog/");
  154. });
  155. }else{
  156. alert("Personal page not enabled");
  157. }
  158. })
  159. }
  160. function openPersonalPageTab(){
  161. ao_module_openSetting("Network", "Personal Page");
  162. }
  163. function checkIfWebRootEnabled(callback){
  164. $.get("../system/network/www/toggle", function(data){
  165. callback(data);
  166. });
  167. }
  168. function getWebRoot(callback = undefined){
  169. $.get("../system/network/www/webRoot", function(data){
  170. if (data == null || data == "" || data == undefined){
  171. callback("");
  172. return;
  173. }
  174. currentWebDeployRoot = data;
  175. if (callback != undefined){
  176. callback(data);
  177. }
  178. });
  179. }
  180. function listPost(){
  181. $("#postList").html(``);
  182. ao_module_agirun("Blog/backend/listPosts.js", {
  183. webroot: currentWebDeployRoot
  184. }, function(data){
  185. if (data.length == 0){
  186. //There is no post in the system
  187. $("#postList").html(`<div class="ts segment post">
  188. <h5 class="ts header">
  189. <div class="content">
  190. No Blog Posts
  191. <div class="sub header">Create your first post with the "New Post"</div>
  192. </div>
  193. </h5>
  194. </div>`);
  195. }else{
  196. //Render the post
  197. console.log(data);
  198. data.forEach(post => {
  199. //Generate the tag HTML
  200. var tags = post.tags;
  201. var tagHTML = [];
  202. tags.forEach(tag => {
  203. tagHTML.push(`<a class="section">${tag}</a>`);
  204. });
  205. tagHTML = tagHTML.join(`<div class="divider">,</div>`);
  206. //Post view permission indicator
  207. var postViewIcon = "";
  208. //Publish or hide post button
  209. var publicPostOnly = "";
  210. var privatePostOnly = "";
  211. if (post.view == "private"){
  212. postViewIcon = `<i class="hide icon"></i> Draft`;
  213. publicPostOnly = "display:none;"
  214. }else{
  215. postViewIcon = `<i class="unhide icon"></i> Published`;
  216. privatePostOnly = "display:none;"
  217. }
  218. $("#postList").append(`<div class="ts segment post">
  219. <div class="ts header">
  220. <a href="#" onclick="openPost(this);" filepath="${post.filepath}">${post.title} </a>
  221. <div class="sub header">
  222. <div>
  223. <span style="padding-right: 1em;">${postViewIcon}</span>
  224. <span style="padding-right: 1em;"><i class="calendar icon"></i> ${post.modtime}</span>
  225. <div class="ts breadcrumb">
  226. <div class="section">
  227. <i class="tag icon"></i>
  228. </div>
  229. ${tagHTML}
  230. </div>
  231. </div>
  232. </div>
  233. </div>
  234. ${stripHtml(post.content)}
  235. <div class="postControls">
  236. <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>
  237. <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>
  238. </div>
  239. </div>`)
  240. })
  241. }
  242. });
  243. function stripHtml(html){
  244. let tmp = document.createElement("DIV");
  245. tmp.innerHTML = html;
  246. var result = tmp.textContent || tmp.innerText || "";
  247. return result;
  248. }
  249. }
  250. </script>
  251. </body>
  252. </html>