web/src/pages/all.astro

206 lines · 4716 bytes

  1---
  2
  3
  4import Layout from '@layouts/Layout.astro';
  5import ServiceList from '@components/things/ServiceList.astro';
  6import type { AwesomePrivacy, Section } from '../types/Service';
  7import { fetchData, slugify } from '@utils/fetch-data';
  8import FontAwesome from '@components/form/FontAwesome.svelte';
  9
 10const categories = (await fetchData() as AwesomePrivacy)?.categories || [];
 11
 12---
 13
 14<script>
 15
 16const toggleSidebar = () => {
 17  const mainContent = document.querySelector('#content');
 18  mainContent && mainContent.classList.toggle('narrow');
 19  const sidebar = document.querySelector('.sidebar');
 20  sidebar && sidebar.classList.toggle('hidden');
 21  const button = document.querySelector('#toggle-sidebar');
 22  if (button) {
 23    button.textContent = (button.textContent === "Show Contents" ? "Hide Contents" : "Show Contents");
 24  }
 25};
 26
 27  const tgt = document.querySelector("#toggle-sidebar");
 28  tgt && tgt.addEventListener("click", () => {
 29    toggleSidebar();
 30  });
 31</script>
 32
 33<Layout title="Awesome Privacy">
 34    <main>
 35    <div id="content">
 36    <button id="toggle-sidebar">Show Contents</button>
 37    {categories.map((category) => (
 38      <h2  id={`${slugify(category.name)}`}>
 39        <FontAwesome iconName={slugify(category.name)} />
 40        <a href={`/${slugify(category.name)}`}>{category.name}</a>
 41      </h2>
 42      
 43        <article>
 44          {category.sections.map((section: Section) => (
 45            <section class="card">
 46              <h3 id={`${slugify(category.name)}-${slugify(section.name)}`}>
 47                <a href={`/${slugify(category.name)}/${slugify(section.name)}`}>{section.name}</a>
 48              </h3>
 49              <ServiceList
 50                services={section.services}
 51                subHeading={true}
 52                buttonLink={`/${slugify(category.name)}/${slugify(section.name)}`}
 53                noGitHubMetrics={true}
 54                sectionName={section.name}
 55                categoryName={category.name}
 56              />
 57            </section>
 58          ))}
 59        </article>
 60      
 61    ))}
 62    </div>
 63    <div class="sidebar hidden">
 64      <p class="sidebar-title">Contents</p>
 65      <ul>
 66        {categories.map((category) => (
 67          <li class="top-level">
 68            <a href={`#${slugify(category.name)}`}>{category.name}</a>  
 69          </li>
 70          <li>
 71            <ul>
 72              {category.sections.map((section: Section) => (
 73                <li>
 74                  <a href={`#${slugify(category.name)}-${slugify(section.name)}`}>{section.name}</a>
 75                </li>
 76              ))}
 77            </ul>
 78          </li>
 79        ))}
 80      </ul>
 81    </div>
 82  </main>
 83  
 84</Layout>
 85
 86<style lang="scss">
 87
 88main {
 89  margin: 2rem auto;
 90  padding: 1rem;
 91  width: 1000px;
 92  max-width: calc(100% - 5rem);
 93
 94  display: flex;
 95  justify-content: space-between;
 96}
 97
 98.narrow {
 99  width: 70%;
100}
101
102.hidden {
103  display: none;
104}
105
106#toggle-sidebar {
107  // float: right;
108  background: none;
109  outline: none;
110  border: none;
111  cursor: pointer;
112  &:hover {
113    text-decoration: underline;
114  }
115}
116
117.sidebar {
118  width: 25%;
119  height: 87vh;
120  overflow: scroll;
121  position: fixed;
122  right: 1rem;
123  border-radius: var(--curve-md);
124  .sidebar-title {
125    text-align: center;
126    font-size: 1.6rem;
127    margin: 0;
128    background: var(--accent-3);
129    color: var(--accent-fg);
130    border: 2px solid var(--foreground);
131    box-shadow: 6px 6px 0 var(--foreground);
132    border-radius: var(--curve-sm);
133    margin: 0 1rem;
134  }
135  ul {
136    list-style: none;
137    padding-left: 1.6rem;
138    a {
139      text-decoration: none;
140      color: var(--foreground);
141      opacity: 0.6;
142      transition: all 0.18s ease-in-out;
143      &:hover {
144        color: var(--accent);
145        opacity: 1;
146      }
147    }
148    li ul {
149      list-style: circle;
150    }
151    .top-level {
152      font-weight: bold;
153      margin-top: 0.5rem;
154      &:hover a {
155        color: var(--accent-3);
156      }
157    }
158  } 
159}
160
161
162.card {
163  margin: 2rem auto 5rem auto;
164  padding: 0 2rem;
165  border: 2px solid var(--foreground);
166  box-shadow: 6px 6px 0 var(--foreground);
167  background: var(--accent-fg);
168}
169
170h2 {
171  margin: 0;
172  font-size: 3rem;
173  text-align: center;
174  opacity: 0.6;
175  display: flex;
176  justify-content: center;
177  align-items: center;
178  gap: 1rem;
179  a {
180    color: var(--accent-3);
181    text-decoration: none;
182  }
183  :global(svg) {
184    width: 3rem;
185    height: 3rem;
186    color: var(--accent-3);
187  }
188}
189
190h3 {
191    font-size: 2rem;
192    margin: -2rem 0 2rem -4rem;
193    box-shadow: 6px 6px 0 var(--foreground);
194    background: var(--accent);
195    color: var(--accent-fg);
196    width: fit-content;
197    padding: 0.25rem 0.5rem;
198    a {
199      color: var(--accent-fg);
200      font-family: "Lekton", sans-serif;
201      text-decoration: none;
202    }
203  }
204
205
206</style>