The namegen5 website.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

140 lines
2.8 KiB

3 years ago
  1. <script>
  2. export let collection = {items: []};
  3. export let narrow = false;
  4. export let selected = "";
  5. let categories = [];
  6. $: {
  7. categories.splice(0);
  8. for (const item of collection.items) {
  9. let category = categories.find(c => c.name === item.metadata.category);
  10. if (category == null) {
  11. category = {name: item.metadata.category, list: []}
  12. categories.push(category);
  13. }
  14. category.list.push({id: item.name, label: item.metadata.name, color: item.metadata.color || "#ffffff"});
  15. }
  16. categories.sort((a,b) => {
  17. if (a.list.length !== b.list.length) {
  18. return b.list.length - a.list.length;
  19. } else {
  20. return b.name.localeCompare(a.name);
  21. }
  22. });
  23. for (const category of categories) {
  24. category.list.sort((a,b) => a.id.localeCompare(b.id));
  25. }
  26. }
  27. </script>
  28. <div class="layout">
  29. <div class="page" class:narrow>
  30. <slot></slot>
  31. </div>
  32. <div class="menu">
  33. <h1>
  34. <a class:selected={selected === "INDEX"} href="/">n.vmaple.dev</a>
  35. </h1>
  36. {#each categories as category (category.name)}
  37. <h2>{category.name}</h2>
  38. {#each category.list as item (item.id)}
  39. <span style="--color: {item.color}">
  40. <a class:selected={selected === item.id} href="/{item.id}">{item.label}</a>
  41. </span>
  42. {/each}
  43. {/each}
  44. </div>
  45. </div>
  46. <style>
  47. div.menu {
  48. position: fixed;
  49. left: 0;
  50. top: 0;
  51. height: 100%;
  52. overflow-y: auto;
  53. box-sizing: border-box;
  54. padding: 0em;
  55. background: #222;
  56. border: 1px solid #000;
  57. width: 12em;
  58. }
  59. div.menu h1 {
  60. font-size: 1.5em;
  61. text-align: center;
  62. padding: 0.5em 0 0 0;
  63. }
  64. div.menu h1 a {
  65. line-height: 1.5em;
  66. }
  67. div.menu h2 {
  68. font-size: 1.15em;
  69. color: #555;
  70. padding: 0.5em 1ch 0 1ch;
  71. margin: 0;
  72. }
  73. div.menu a {
  74. display: block;
  75. padding: 0.125em 2ch;
  76. line-height: 1.5em;
  77. text-decoration: none;
  78. font-size: 0.9em;
  79. color: #aaa;
  80. }
  81. div.menu a.selected {
  82. background: #2a2a2a;
  83. color: var(--color);
  84. padding-left: 2.5ch;
  85. }
  86. div.menu a:hover {
  87. background: #191919;
  88. }
  89. div.layout {
  90. padding-left: 12em;
  91. }
  92. div.page {
  93. width: 120ch;
  94. max-width: 90%;
  95. box-sizing: border-box;
  96. margin: 2em auto;
  97. background: #222;
  98. border: 1px solid #000;
  99. border-radius: 1em;
  100. padding: 1em;
  101. text-align: center;
  102. }
  103. div.page.narrow {
  104. width: 75ch;
  105. }
  106. @media screen and (max-width: 720px) {
  107. div.layout {
  108. padding-left: 0;
  109. }
  110. div.menu {
  111. position: initial;
  112. width: 32ch;
  113. max-width: 90%;
  114. margin: 2em auto;
  115. background: #222;
  116. border: 1px solid #000;
  117. border-radius: 1em;
  118. padding: 1em;
  119. text-align: center;
  120. }
  121. div.menu a.selected {
  122. padding-left: 2ch;
  123. font-weight: 600;
  124. }
  125. }
  126. </style>