web/src/pages/sitemap.astro

234 lines · 6533 bytes

  1---
  2
  3
  4import Layout from '@layouts/Layout.astro';
  5import type { AwesomePrivacy } from '../types/Service';
  6import { fetchData, slugify } from '@utils/fetch-data';
  7
  8const categories = (await fetchData() as AwesomePrivacy)?.categories || [];
  9
 10---
 11
 12<Layout title="All Links | Awesome Privacy">
 13    <main>
 14      <h2>Sitemap</h2>
 15      <p>
 16        Below is a full listing of all pages on this site.<br>
 17        <small>As reflected in our <a href="/sitemap-index.xml">sitemap.xml</a></small>
 18      </p>
 19      <span class="search-controlls">
 20        <input id="searchInput" type="search" placeholder="Start typing to filter..." />
 21        <p id="press-enter-msg" class="press-enter">Press enter for deep search</p>
 22      </span>
 23      <ul>
 24        <li>
 25          <a href="/">Home</a>
 26        </li>
 27        <li>
 28          <a href="/search">Search</a>
 29        </li>
 30        <li>
 31          <a href="/all">View All</a>
 32        </li>
 33        <li>
 34          <a href="/inventory">My Inventory</a>
 35        </li>
 36        <li>
 37          <a href="/submit">Submit Listing</a>
 38        </li>
 39        <li>
 40          <a href="/api">API</a>
 41        </li>
 42        <li>
 43          <a href="/browse">Categories</a>
 44          <ul>
 45            {categories.map((category) => (
 46              <li>
 47                <a href={`/${slugify(category.name)}`}>{category.name}</a>
 48                <ul>
 49                  {category.sections.map((section) => (
 50                    <li>
 51                      <a href={`/${slugify(category.name)}/${slugify(section.name)}`}>{section.name}</a>
 52                      <ul>
 53                        {(section.services || []).map((service) => (
 54                          <li title={service.description || ''}>
 55                            <a href={`/${slugify(category.name)}/${slugify(section.name)}/${slugify(service.name)}`}>
 56                              {service.name}
 57                            </a>
 58                          </li>
 59                        ))}
 60                      </ul>
 61                    </li>
 62                  ))}  
 63                </ul>
 64              </li>
 65            ))}
 66          </ul>
 67        </li>
 68        <li>
 69          <a href="/about">About</a>
 70          <ul>
 71            <li><a href="/about#objective">Objective</a></li>
 72            <li><a href="/about#criteria">Listing Criteria</a></li>
 73            <li><a href="/about#contributing">Contributing</a></li>
 74            <li>
 75              <a href="/about#acknowledgements">Acknowledgements</a>
 76              <ul>
 77                <li><a href="/about#contributors">Contributors</a></li>
 78                <li><a href="/about#sponsors">Sponsors</a></li>
 79              </ul>
 80            </li>
 81            <li><a href="/about#author">Author</a></li>
 82            <li><a href="/about#license">License</a></li>
 83          </ul>
 84        </li>
 85        <li>
 86          <a href="/sitemap">Sitemap</a>
 87        </li>
 88      </ul>
 89  </main>
 90  
 91</Layout>
 92
 93<script>
 94  document.addEventListener('DOMContentLoaded', () => {
 95    // Select elements for events (search field, each result, and message str)
 96    const filterInput = document.querySelector<HTMLInputElement>('input');
 97    const pages = document.querySelectorAll<HTMLElement>('li');
 98    const pressEnterMsg = document.getElementById('press-enter-msg');
 99    if (!pressEnterMsg) throw new Error('pressEnterMsg element not found');
100
101    // Instant search/filter functionality
102    filterInput?.addEventListener('input', (e: Event) => {
103      const filter = (e.target as HTMLInputElement).value.toLowerCase();
104      pressEnterMsg.style.visibility = filter.length > 0 ? 'visible' : 'hidden';
105      Array.from(pages).reduce((count, page) => {
106        const match = page.textContent?.toLowerCase().includes(filter) || false;
107        page.style.display = match ? 'block' : 'none';
108        return count + (match ? 1 : 0);
109      }, 0);
110    });
111    // Handle keypress events, so Esc clears search, and Entr runs deep search
112    document.addEventListener('keydown', (event: KeyboardEvent) => {
113      if (!filterInput) return;
114      switch (event.key) {
115        case 'Enter':
116          event.preventDefault();
117          const searchTerm = encodeURIComponent(filterInput.value);
118          window.location.href = `/search/${searchTerm}`;
119          break;
120        case 'Escape':
121          filterInput.value = '';
122          filterInput.blur();
123          pressEnterMsg.style.visibility = 'hidden';
124          pages.forEach(page => page.style.display = 'block');
125          break;
126      }
127    });
128  });
129</script>
130
131<style lang="scss">
132
133main {
134  padding: 1rem;
135  width: 1000px;
136  max-width: calc(100% - 5rem);
137  margin: 4rem auto 5rem auto;
138  padding: 0 2rem;
139  border: 2px solid var(--box-outline);
140  box-shadow: 6px 6px 0 var(--box-outline);
141  background: var(--accent-fg);
142  position: relative;
143  p {
144    font-size: 1.3rem;
145    margin: 0;
146    small {
147      font-size: 0.8rem;
148      opacity: 0.5;
149      transition: all 0.2s ease-in-out;
150      &:hover { opacity: 0.8; }
151    }
152  }
153  ul {
154    padding-left: 1.2rem;
155    list-style: none;
156    border-left: 3px solid #5f53f482;
157    border-radius: 4px;;
158    li {
159      font-weight: 600;
160        ul li {
161          font-weight: 500;
162          ul li {
163            font-weight: 400;
164            ul li {
165              font-weight: 300;
166            }
167          }
168        }
169      &::before {
170        content: "━ ";
171        color: #5f53f482;
172        margin-left: -1.2rem;
173      }
174      a {
175        transition: all ease-in-out 0.2s;
176        text-decoration: none;
177        &:hover {
178          text-decoration: underline;
179        }
180      }
181    }
182  }
183}
184
185h2 {
186  margin: 0;
187  gap: 1rem;
188  font-size: 2rem;
189  margin: -2rem 0 2rem -4rem;
190  box-shadow: 6px 6px 0 var(--box-outline);
191  background: var(--accent);
192  color: var(--accent-fg);
193  width: fit-content;
194  padding: 0.25rem 0.5rem;
195  @media (max-width: 768px) {
196    margin: -2rem auto 1rem auto;
197  }
198}
199
200.search-controlls {
201  float: right;
202  top: 1rem;
203  right: 1rem;
204  position: absolute;
205  @media (max-width: 768px) {
206    position: relative;
207    float: none;
208    top: 0;
209    right: 0;
210  }
211  .press-enter {
212    margin: 0.5rem 0 0 0;
213    opacity: 0.5;
214    visibility: hidden;
215    font-size: 1rem;
216  }
217  input {
218    padding: 0.25rem;
219    border: 2px solid var(--box-outline);
220    border-radius: var(--curve-sm);
221    font-size: 1rem;
222    box-shadow: 3px 3px 0 var(--box-outline);
223    color: var(--accent-3);
224    background: var(--background-form);
225    &:focus {
226      outline: none;
227      box-shadow: 4px 4px 0 var(--box-outline);
228    }
229  }
230}
231
232
233
234</style>