index.html 7.3 KB

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