library.html 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. // first the titles
  18. var title = rules[i]["communityname"];
  19. if (title == null) { title = "Untitled"; }
  20. libHTML += "<div class='library-rule-name'>" +
  21. "<a href='/create/?r=" + rules[i]["ruleID"] + "'>" +
  22. title + "</a></div>\n";
  23. // then the authors
  24. var author = rules[i]["author-text"];
  25. if (author != null) {
  26. libHTML += "<div class='library-rule-author'>" + author + "</div>";
  27. }
  28. // then the structures
  29. var structure = rules[i]["structure"];
  30. if (structure != null) {
  31. libHTML += "<p class='library-rule-structure'>" + structure;
  32. libHTML += "</p>\n\n";
  33. }
  34. // then the modules
  35. var modulesRaw = rules[i]["modules"];
  36. if (modulesRaw != null) {
  37. libHTML += "<div class='library-module-list'>";
  38. var modulesDOM = document.createElement("DIV");
  39. modulesDOM.innerHTML = "<div>" + modulesRaw + "</div>";
  40. var modules = modulesDOM.getElementsByClassName("module");
  41. for (var x = 0; x < modules.length; x++) {
  42. var moduleName = modules[x].children.item("module-name").innerHTML;
  43. libHTML += "<div class='module library-module'>" +
  44. moduleName + "</div>\n";
  45. }
  46. moduleName + "</div>\n";
  47. }
  48. libHTML += "</div>\n</div>\n";
  49. }
  50. libHTML += "</div>\n";
  51. document.getElementById("librarylist").innerHTML = libHTML;
  52. });
  53. }
  54. // allows for using alt sheets
  55. var source = "";
  56. window.onload = function() {
  57. if ((window.location.href.indexOf("/library/") != -1)) {
  58. source = "rules";
  59. } else if ((window.location.href.indexOf("/templates/") != -1)) {
  60. source = "templates";
  61. }
  62. printLibrary(source);
  63. }
  64. </script>
  65. <article class="post">
  66. <header class="post-header">
  67. <h1 class="post-title">{{ page.title }}</h1>
  68. </header>
  69. <div class="post-content">
  70. {{ content }}
  71. <div id="librarylist">
  72. </div>
  73. </div>
  74. </article>