library.html 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. ---
  2. layout: default
  3. ---
  4. <script>
  5. // Main Library-printing function
  6. function printLibrary(sheet) {
  7. const store = new SteinStore(
  8. "https://api.steinhq.com/v1/storages/5e8b937ab88d3d04ae0816a5"
  9. );
  10. var rules = "";
  11. store.read(sheet, { limit: 0, offset: 0 }).then(data => {
  12. rules = data.reverse();
  13. libHTML = "";
  14. // iterating over all the rules
  15. for (var i = 0; i < rules.length; i++) {
  16. libHTML += "<div class='library-item'>\n";
  17. // icon if there is one
  18. var icon = rules[i]["icon"];
  19. var iconHTML = "";
  20. if (icon != null) {
  21. iconHTML = "<img src='/assets/elements/" + icon + "' />";
  22. }
  23. // first the titles
  24. var title = rules[i]["communityname"];
  25. if (title == null) { title = "Untitled"; }
  26. libHTML += "<h2 class='library-rule-name'>" +
  27. "<a href='/create/?r=" + rules[i]["ruleID"] + "'>" + iconHTML +
  28. title + "</a></h2>\n";
  29. // then the authors
  30. var author = rules[i]["author-text"];
  31. if (author != null) {
  32. libHTML += "<div class='library-rule-author'>" + author + "</div>";
  33. }
  34. // then the structures
  35. var structure = rules[i]["structure"];
  36. if (structure != null) {
  37. libHTML += "<p class='library-rule-structure'>" + structure;
  38. libHTML += "</p>\n\n";
  39. }
  40. // then the modules
  41. var modulesRaw = rules[i]["modules"];
  42. if (modulesRaw != null) {
  43. libHTML += "<div class='library-module-list'>";
  44. var modulesDOM = document.createElement("DIV");
  45. modulesDOM.innerHTML = "<div>" + modulesRaw + "</div>";
  46. var modules = modulesDOM.getElementsByClassName("module");
  47. for (var x = 0; x < modules.length; x++) {
  48. var moduleName = modules[x].children.item("module-name").innerHTML;
  49. libHTML += "<div class='module library-module'>" +
  50. moduleName + "</div>\n";
  51. }
  52. moduleName + "</div>\n";
  53. }
  54. libHTML += "</div>\n</div>\n";
  55. }
  56. libHTML += "</div>\n";
  57. document.getElementById("librarylist").innerHTML = libHTML;
  58. });
  59. }
  60. // allows for using alt sheets
  61. var source = "";
  62. window.onload = function() {
  63. if ((window.location.href.indexOf("/library/") != -1)) {
  64. source = "library";
  65. } else if ((window.location.href.indexOf("/templates/") != -1)) {
  66. source = "templates";
  67. }
  68. printLibrary(source);
  69. }
  70. </script>
  71. <article class="post">
  72. <header class="post-header">
  73. <h1 class="post-title">{{ page.title }}</h1>
  74. </header>
  75. <div class="post-content">
  76. {{ content }}
  77. <div id="librarylist">
  78. </div>
  79. </div>
  80. </article>