library.html 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 (though rule.html is not equipped)
  55. var source = "";
  56. window.onload = function() {
  57. if ((window.location.href.indexOf("/library/") != -1)) {
  58. source = "rules";
  59. }
  60. printLibrary(source);
  61. }
  62. </script>
  63. <article class="post">
  64. <header class="post-header">
  65. <h1 class="post-title">{{ page.title }}</h1>
  66. </header>
  67. <div class="post-content">
  68. {{ content }}
  69. <div id="librarylist">
  70. </div>
  71. </div>
  72. </article>