library.html 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 = "<span class='icon'><img src='" + icon + "' /></span>";
  22. }
  23. // first the titles
  24. var title = rules[i]["name"];
  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]["creatorName"];
  31. if (author != null) {
  32. libHTML += "<div class='library-rule-author'>" + author + "</div>";
  33. }
  34. // then the structures
  35. var structure = rules[i]["summary"];
  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 modules__grid'>";
  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. printLibrary('rules');
  64. }
  65. </script>
  66. <article class="post">
  67. <header class="post-header">
  68. <h1 class="post-title">{{ page.title }}</h1>
  69. </header>
  70. <div class="post-content">
  71. {{ content }}
  72. <div id="librarylist">
  73. </div>
  74. </div>
  75. </article>