web/src/pages/sitemap.astro

244 lines · 5909 bytes

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