post.html 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>PostEngine Pro</title>
  6. <meta name="viewport" content="width=device-width, initial-scale=1" >
  7. <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
  8. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.css" />
  9. <script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.js"></script>
  10. <style>
  11. body{
  12. background-color: rgb(243, 243, 243);
  13. border-top: 1px solid #70aeff;
  14. }
  15. .ui.vertical.menu{
  16. width: calc(15em - 3px) !important;
  17. }
  18. .postengine_context{
  19. padding-left: calc(15em + 1px) !important;
  20. }
  21. #msgbox_snackbar {
  22. min-width: 240px;
  23. position: fixed;
  24. bottom: 20px;
  25. right: 20px;
  26. background-color: #323232;
  27. color: white;
  28. padding: 16px;
  29. border-radius: 4px;
  30. display: none;
  31. z-index: 1000;
  32. }
  33. </style>
  34. </head>
  35. <body>
  36. <div class="ui container">
  37. </div>
  38. <div id="postengine_side_menu" class="ui left fixed inverted vertical menu">
  39. <div class="item" style="pointer-events: none;">
  40. <img class="ui fluid image" src="./img/post-engine.svg">
  41. </div>
  42. <div class="item">
  43. <div class="header">Posts</div>
  44. <div class="menu">
  45. <a class="item active" name="allposts" xtab="posteng/all.html">All Posts</a>
  46. <a class="item" name="newpost" xtab="posteng/new.html">Add New</a>
  47. </div>
  48. </div>
  49. <div class="item">
  50. <div class="header">Media</div>
  51. <div class="menu">
  52. <a class="item" name="library" xtab="posteng/library.html">Image Library</a>
  53. <a class="item" name="paste" xtab="posteng/paste.html">Image Paste</a>
  54. </div>
  55. </div>
  56. <div class="item">
  57. <div class="header">Pages</div>
  58. <div class="menu">
  59. <a class="item" name="allpages" xtab="posteng/pages.html">All Pages</a>
  60. <a class="item" name="newpage" xtab="posteng/newpg.html">Add New</a>
  61. </div>
  62. </div>
  63. <div class="item">
  64. <div class="header">Settings</div>
  65. <div class="menu">
  66. <a class="item" name="settings" xtab="posteng/setting.html">General</a>
  67. <!-- <a class="item" name="permlinks" xtab="">Permalinks</a> -->
  68. </div>
  69. </div>
  70. </div>
  71. <!-- Function Tabs -->
  72. <div id="postengine_tab" class="postengine_context"></div>
  73. <!-- msgbox snackbar -->
  74. <div id="msgbox_snackbar">
  75. <span id="msgbox_text">This is a message</span>
  76. </div>
  77. <script>
  78. var editingPost = ""; //The name of the post being edited, if empty = new post
  79. var editingPage = "";
  80. $("#postengine_tab").load("posteng/all.html");
  81. // Add event listener to menu items with target attribute
  82. $("#postengine_side_menu .item[xtab]").on("click", function() {
  83. var targetId = $(this).attr("xtab");
  84. $("#postengine_side_menu .item.active").removeClass("active");
  85. $(this).addClass("active");
  86. //Load the xtab url into the postengine_tab div
  87. $("#postengine_tab").load(targetId, function() {
  88. // Callback function after loading the content
  89. // You can add any additional logic here if needed
  90. console.log("Loaded: " + targetId);
  91. });
  92. });
  93. function switchToTab(tabName) {
  94. switch(tabName) {
  95. case "allposts":
  96. $("#postengine_tab").load("posteng/all.html");
  97. break;
  98. case "newpost":
  99. $("#postengine_tab").load("posteng/new.html");
  100. break;
  101. case "library":
  102. $("#postengine_tab").load("posteng/library.html");
  103. break;
  104. case "paste":
  105. $("#postengine_tab").load("posteng/paste.html");
  106. break;
  107. case "allpages":
  108. $("#postengine_tab").load("posteng/pages.html");
  109. break;
  110. case "newpage":
  111. $("#postengine_tab").load("posteng/newpage.html");
  112. break;
  113. case "settings":
  114. $("#postengine_tab").load("posteng/settings.html");
  115. break;
  116. case "permlinks":
  117. $("#postengine_tab").load("posteng/permalinks.html");
  118. break;
  119. }
  120. // Update the active class on the menu items
  121. $("#postengine_side_menu .item.active").removeClass("active");
  122. $("#postengine_side_menu .item[name='" + tabName + "']").addClass("active");
  123. }
  124. function msgbox(message, duration = 3000) {
  125. const snackbar = document.getElementById("msgbox_snackbar");
  126. const text = document.getElementById("msgbox_text");
  127. $(text).html(message);
  128. $(snackbar).fadeIn("fast").delay(duration).fadeOut("fast");
  129. }
  130. /*
  131. Common post management features
  132. */
  133. //Storage and loader utils to load from pref database
  134. //the perf database is a key-value store that only
  135. //writable when logged in but readable by everyone
  136. function setValue(key, value, callback){
  137. $.get("/api/pref/set?key=" + key + "&value=" + value, function(data){
  138. callback(data);
  139. });
  140. }
  141. function loadValue(key, callback){
  142. $.get("/api/pref/get?key=" + key, function(data){
  143. callback(data);
  144. });
  145. }
  146. //Update the post index in the server side
  147. function updatePostIndex(callback=undefined){
  148. let postList = [];
  149. $.ajax({
  150. url: "/api/fs/list?dir=/site/posts",
  151. success: function(data){
  152. data.forEach(file => {
  153. let filename = file.Filename;
  154. let ext = filename.split(".").pop();
  155. if (ext == "md" && file.IsDir == false){
  156. //Markdown file. Render it
  157. postList.push(filename);
  158. }
  159. });
  160. //Set the
  161. setValue("site-posts", btoa(encodeURIComponent(JSON.stringify(postList))), function(data){
  162. console.log(data);
  163. if (callback != undefined){
  164. callback();
  165. }
  166. });
  167. }
  168. });
  169. }
  170. </script>
  171. </body>
  172. </html>