post.html 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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" xtab="posteng/all.html">All Posts</a>
  46. <a class="item" 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" xtab="">Library</a>
  53. <a class="item" xtab="">Add New</a>
  54. </div>
  55. </div>
  56. <div class="item">
  57. <div class="header">Pages</div>
  58. <div class="menu">
  59. <a class="item" xtab="">All Pages</a>
  60. <a class="item" 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" xtab="">General</a>
  67. <a class="item" 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. let 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 msgbox(message, duration = 3000) {
  93. const snackbar = document.getElementById("msgbox_snackbar");
  94. const text = document.getElementById("msgbox_text");
  95. text.textContent = message;
  96. snackbar.style.display = "block";
  97. setTimeout(() => {
  98. snackbar.style.display = "none";
  99. }, duration);
  100. }
  101. /*
  102. Common post management features
  103. */
  104. //Storage and loader utils to load from pref database
  105. //the perf database is a key-value store that only
  106. //writable when logged in but readable by everyone
  107. function setValue(key, value, callback){
  108. $.get("/api/pref/set?key=" + key + "&value=" + value, function(data){
  109. callback(data);
  110. });
  111. }
  112. function loadValue(key, callback){
  113. $.get("/api/pref/get?key=" + key, function(data){
  114. callback(data);
  115. });
  116. }
  117. //Update the post index in the server side
  118. function updatePostIndex(callback=undefined){
  119. let postList = [];
  120. $.ajax({
  121. url: "/api/fs/list?dir=/site/posts",
  122. success: function(data){
  123. data.forEach(file => {
  124. let filename = file.Filename;
  125. let ext = filename.split(".").pop();
  126. if (ext == "md" && file.IsDir == false){
  127. //Markdown file. Render it
  128. postList.push(filename);
  129. }
  130. });
  131. //Set the
  132. setValue("site-posts", btoa(encodeURIComponent(JSON.stringify(postList))), function(data){
  133. console.log(data);
  134. if (callback != undefined){
  135. callback();
  136. }
  137. });
  138. }
  139. });
  140. }
  141. </script>
  142. </body>
  143. </html>