post.html 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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="">Convert</a>
  53. <a class="item" name="paste" xtab="">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="">All Pages</a>
  60. <a class="item" name="newpage" xtab="">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="">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. $("#postengine_tab").load("posteng/all.html");
  80. // Add event listener to menu items with target attribute
  81. $("#postengine_side_menu .item[xtab]").on("click", function() {
  82. var targetId = $(this).attr("xtab");
  83. $("#postengine_side_menu .item.active").removeClass("active");
  84. $(this).addClass("active");
  85. //Load the xtab url into the postengine_tab div
  86. $("#postengine_tab").load(targetId, function() {
  87. // Callback function after loading the content
  88. // You can add any additional logic here if needed
  89. console.log("Loaded: " + targetId);
  90. });
  91. });
  92. function switchToTab(tabName) {
  93. switch(tabName) {
  94. case "allposts":
  95. $("#postengine_tab").load("posteng/all.html");
  96. break;
  97. case "newpost":
  98. $("#postengine_tab").load("posteng/new.html");
  99. break;
  100. case "library":
  101. $("#postengine_tab").load("posteng/library.html");
  102. break;
  103. case "paste":
  104. $("#postengine_tab").load("posteng/paste.html");
  105. break;
  106. case "allpages":
  107. $("#postengine_tab").load("posteng/pages.html");
  108. break;
  109. case "newpage":
  110. $("#postengine_tab").load("posteng/newpage.html");
  111. break;
  112. case "settings":
  113. $("#postengine_tab").load("posteng/settings.html");
  114. break;
  115. case "permlinks":
  116. $("#postengine_tab").load("posteng/permalinks.html");
  117. break;
  118. }
  119. // Update the active class on the menu items
  120. $("#postengine_side_menu .item.active").removeClass("active");
  121. $("#postengine_side_menu .item[name='" + tabName + "']").addClass("active");
  122. }
  123. function msgbox(message, duration = 3000) {
  124. const snackbar = document.getElementById("msgbox_snackbar");
  125. const text = document.getElementById("msgbox_text");
  126. text.textContent = message;
  127. $(snackbar).fadeIn("fast").delay(duration).fadeOut("fast");
  128. }
  129. /*
  130. Common post management features
  131. */
  132. //Storage and loader utils to load from pref database
  133. //the perf database is a key-value store that only
  134. //writable when logged in but readable by everyone
  135. function setValue(key, value, callback){
  136. $.get("/api/pref/set?key=" + key + "&value=" + value, function(data){
  137. callback(data);
  138. });
  139. }
  140. function loadValue(key, callback){
  141. $.get("/api/pref/get?key=" + key, function(data){
  142. callback(data);
  143. });
  144. }
  145. //Update the post index in the server side
  146. function updatePostIndex(callback=undefined){
  147. let postList = [];
  148. $.ajax({
  149. url: "/api/fs/list?dir=/site/posts",
  150. success: function(data){
  151. data.forEach(file => {
  152. let filename = file.Filename;
  153. let ext = filename.split(".").pop();
  154. if (ext == "md" && file.IsDir == false){
  155. //Markdown file. Render it
  156. postList.push(filename);
  157. }
  158. });
  159. //Set the
  160. setValue("site-posts", btoa(encodeURIComponent(JSON.stringify(postList))), function(data){
  161. console.log(data);
  162. if (callback != undefined){
  163. callback();
  164. }
  165. });
  166. }
  167. });
  168. }
  169. </script>
  170. </body>
  171. </html>