web/src/pages/all.astro

205 lines · 4665 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                title={section.name}
 51                services={section.services}
 52                subHeading={true}
 53                buttonLink={`/${slugify(category.name)}/${slugify(section.name)}`}
 54                noGitHubMetrics={true}
 55              />
 56            </section>
 57          ))}
 58        </article>
 59      
 60    ))}
 61    </div>
 62    <div class="sidebar hidden">
 63      <p class="sidebar-title">Contents</p>
 64      <ul>
 65        {categories.map((category) => (
 66          <li class="top-level">
 67            <a href={`#${slugify(category.name)}`}>{category.name}</a>  
 68          </li>
 69          <li>
 70            <ul>
 71              {category.sections.map((section: Section) => (
 72                <li>
 73                  <a href={`#${slugify(category.name)}-${slugify(section.name)}`}>{section.name}</a>
 74                </li>
 75              ))}
 76            </ul>
 77          </li>
 78        ))}
 79      </ul>
 80    </div>
 81  </main>
 82  
 83</Layout>
 84
 85<style lang="scss">
 86
 87main {
 88  margin: 2rem auto;
 89  padding: 1rem;
 90  width: 1000px;
 91  max-width: calc(100% - 5rem);
 92
 93  display: flex;
 94  justify-content: space-between;
 95}
 96
 97.narrow {
 98  width: 70%;
 99}
100
101.hidden {
102  display: none;
103}
104
105#toggle-sidebar {
106  // float: right;
107  background: none;
108  outline: none;
109  border: none;
110  cursor: pointer;
111  &:hover {
112    text-decoration: underline;
113  }
114}
115
116.sidebar {
117  width: 25%;
118  height: 87vh;
119  overflow: scroll;
120  position: fixed;
121  right: 1rem;
122  border-radius: var(--curve-md);
123  .sidebar-title {
124    text-align: center;
125    font-size: 1.6rem;
126    margin: 0;
127    background: var(--accent-3);
128    color: var(--accent-fg);
129    border: 2px solid var(--foreground);
130    box-shadow: 6px 6px 0 var(--foreground);
131    border-radius: var(--curve-sm);
132    margin: 0 1rem;
133  }
134  ul {
135    list-style: none;
136    padding-left: 1.6rem;
137    a {
138      text-decoration: none;
139      color: var(--foreground);
140      opacity: 0.6;
141      transition: all 0.18s ease-in-out;
142      &:hover {
143        color: var(--accent);
144        opacity: 1;
145      }
146    }
147    li ul {
148      list-style: circle;
149    }
150    .top-level {
151      font-weight: bold;
152      margin-top: 0.5rem;
153      &:hover a {
154        color: var(--accent-3);
155      }
156    }
157  } 
158}
159
160
161.card {
162  margin: 2rem auto 5rem auto;
163  padding: 0 2rem;
164  border: 2px solid var(--foreground);
165  box-shadow: 6px 6px 0 var(--foreground);
166  background: var(--accent-fg);
167}
168
169h2 {
170  margin: 0;
171  font-size: 3rem;
172  text-align: center;
173  opacity: 0.6;
174  display: flex;
175  justify-content: center;
176  align-items: center;
177  gap: 1rem;
178  a {
179    color: var(--accent-3);
180    text-decoration: none;
181  }
182  :global(svg) {
183    width: 3rem;
184    height: 3rem;
185    color: var(--accent-3);
186  }
187}
188
189h3 {
190    font-size: 2rem;
191    margin: -2rem 0 2rem -4rem;
192    box-shadow: 6px 6px 0 var(--foreground);
193    background: var(--accent);
194    color: var(--accent-fg);
195    width: fit-content;
196    padding: 0.25rem 0.5rem;
197    a {
198      color: var(--accent-fg);
199      font-family: "Lekton", sans-serif;
200      text-decoration: none;
201    }
202  }
203
204
205</style>