index.html 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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.red{
  54. background-color: #c4413d;
  55. border: 1px solid #c4413d;
  56. color: white;
  57. }
  58. .blog.red:hover{
  59. background-color: #8c302d !important;
  60. border: 1px solid #8c302d !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> Browse Blog</button>
  84. <div class="ts divider"></div>
  85. <button class="ts fluid small button"><i class="folder open icon"></i> Open Folder</button>
  86. <button class="ts fluid small button topPad"><i class="setting icon"></i> Settings</button>
  87. </div>
  88. </div>
  89. </div>
  90. <br><br><br>
  91. </div>
  92. <script>
  93. //List all the post stored in the system
  94. listPost();
  95. function openPost(object){
  96. //Parse the file object following ArozOS file descriptor protocol
  97. var filepath = $(object).attr("filepath");
  98. var filename = filepath.split("/").pop();
  99. var file = [{
  100. filename: filename,
  101. filepath: filepath
  102. }]
  103. var fd = encodeURIComponent(JSON.stringify(file));
  104. window.location.href = "editor.html#" + fd;
  105. }
  106. function listPost(){
  107. ao_module_agirun("Blog/backend/listPosts.js", {}, function(data){
  108. if (data.length == 0){
  109. //There is no post in the system
  110. $("#postList").html(`<div class="ts segment post">
  111. <h5 class="ts header">
  112. <div class="content">
  113. No Blog Posts
  114. <div class="sub header">Create your first post with the "New Post"</div>
  115. </div>
  116. </h5>
  117. </div>`);
  118. }else{
  119. //Render the post
  120. console.log(data);
  121. data.forEach(post => {
  122. //Generate the tag HTML
  123. var tags = post.tags;
  124. var tagHTML = [];
  125. tags.forEach(tag => {
  126. tagHTML.push(`<a class="section">${tag}</a>`);
  127. });
  128. tagHTML = tagHTML.join(`<div class="divider">,</div>`);
  129. //Post view permission indicator
  130. var postViewIcon = "";
  131. //Publish or hide post button
  132. var publicPostOnly = "";
  133. var privatePostOnly = "";
  134. if (post.view == "private"){
  135. postViewIcon = `<i class="hide icon"></i> Draft`;
  136. publicPostOnly = "display:none;"
  137. }else{
  138. postViewIcon = `<i class="unhide icon"></i> Published`;
  139. privatePostOnly = "display:none;"
  140. }
  141. $("#postList").append(`<div class="ts segment post">
  142. <div class="ts header">
  143. <a href="#" onclick="openPost(this);" filepath="${post.filepath}">${post.title} </a>
  144. <div class="sub header">
  145. <div>
  146. <span style="padding-right: 1em;">${postViewIcon}</span>
  147. <span style="padding-right: 1em;"><i class="calendar icon"></i> ${post.modtime}</span>
  148. <div class="ts breadcrumb">
  149. <div class="section">
  150. <i class="tag icon"></i>
  151. </div>
  152. ${tagHTML}
  153. </div>
  154. </div>
  155. </div>
  156. </div>
  157. ${stripHtml(post.content)}
  158. <div class="postControls">
  159. <button style="${publicPostOnly}" class="ts mini icon button blog red" title="Hide Post"><i class="hide icon"></i></button>
  160. <button style="${privatePostOnly}" class="ts mini icon button blog green" title="Publish Post"><i class="upload icon"></i></button>
  161. </div>
  162. </div>`)
  163. })
  164. }
  165. });
  166. function stripHtml(html){
  167. let tmp = document.createElement("DIV");
  168. tmp.innerHTML = html;
  169. var result = tmp.textContent || tmp.innerText || "";
  170. return result;
  171. }
  172. }
  173. </script>
  174. </body>
  175. </html>