Commit 73ec5fdbc1

73ec5fdbc17255af86611f84915addaedc81be70

parent: 92f2750a0d

Unsigned

Alicia Sykes <alicia@omg.lol> · 2024-02-17 16:46 UTC

Built out all the main pages

Layout: unified · split

web/src/pages/[...section].astro +192 −39
@@ -1,68 +1,221 @@
1--- 1---
2 2
3import yaml from 'js-yaml';
4 3
5import Layout from '../layouts/Layout.astro'; 4import Layout from '@layouts/Layout.astro';
6import Card from '../components/Card.astro'; 5import Button from '@components/form/Button.astro';
7import Hero from '../components/Hero.astro'; 6import Main from '@components/scafold/MainCard.astro';
8import { AwesomePrivacy, Section, Service } from '../types/Service'; 7import ServiceList from '@components/things/ServiceList.astro';
8import type { AwesomePrivacy, Section, Service, ShortService } from '../types/Service';
9import { fetchData, slugify } from '@utils/fetch-data';
10import { parseMarkdown } from '@utils/parse-markdown';
11
12interface Props {
13 slug: string,
14 title: string,
15 services: Service[],
16 intro?: string,
17 notableMentions?: ShortService[] | string,
18 furtherInfo?: string,
19 wordOfWarning?: string,
20 categoryName: string,
21 otherSections: Section[],
22}
9 23
10const { title, otherSections, services } = Astro.props; 24const { slug, title, otherSections, services, notableMentions, furtherInfo, wordOfWarning, categoryName, intro } = Astro.props;
11 25
12export async function getStaticPaths() { 26export async function getStaticPaths() {
13 27
14const fetchData = async (): Promise<AwesomePrivacy> => {
15 return await fetch('http://localhost:4321/awesome-privacy.yml')
16 .then((res) => res.text())
17 .then((data) => yaml.load(data))
18 .catch((err) => console.error(err));
19};
20
21
22const slugify = (title: string) => {
23 return title.toLowerCase().replace(/\s/g, '-');
24};
25
26
27const pages = await fetchData().then((data) => { 28const pages = await fetchData().then((data) => {
28 29 const results: Array<Props> = [];
29 const results: { slug: string, title: string, otherSections: Section[], services: Service[] }[] = []; 30 (data as AwesomePrivacy).categories.forEach((category) => {
30 data.categories.forEach((service) => { 31 const sections = category.sections.map((section) => ({
31 const sections = service.sections.map((section) => ({ 32 slug: `${slugify(category.name)}/${slugify(section.name)}`,
32 slug: `${slugify(service.name)}/${slugify(section.name)}`,
33 title: section.name, 33 title: section.name,
34 services: section.services, 34 services: section.services,
35 otherSections: service.sections, 35 intro: section.intro,
36 notableMentions: section.notableMentions,
37 furtherInfo: section.furtherInfo,
38 wordOfWarning: section.wordOfWarning,
39 categoryName: category.name,
40 otherSections: category.sections,
36 })); 41 }));
37 results.push(...sections); 42 results.push(...sections);
38 }); 43 });
39 return results; 44 return results;
40}); 45});
41 46
42return pages.map(({ slug, title, otherSections, services }) => { 47return pages.map(({ slug, title, otherSections, services, notableMentions, furtherInfo, wordOfWarning, categoryName, intro }) => {
43 return { 48 return {
44 params: { section: slug }, 49 params: { section: slug },
45 props: { title, otherSections, services }, 50 props: { title, otherSections, services, notableMentions, furtherInfo, wordOfWarning, categoryName, intro },
46 }; 51 };
47}); 52});
48
49} 53}
50 54
55const makePaginationLinks = () => {
56 const index = otherSections.findIndex(section => section.name === title);
57 const previousSection = index > 0 ? otherSections[index - 1].name : null;
58 const nextSection = index < otherSections.length - 1 ? otherSections[index + 1].name : null;
59 return { previous: previousSection, next: nextSection };
60};
61
62const { previous, next } = makePaginationLinks();
63
51--- 64---
52 65
53<Layout title="Awesome Privacy"> 66<Layout title="Awesome Privacy">
54 67 <Main>
55 <h1>{title}</h1> 68
69 <h2>{title}</h2>
70
71 {intro && (
72 <section class="intro">
73 <p set:html={parseMarkdown(intro)}></p>
74 </section>
75 )}
76
77 <ServiceList title={title} services={services} />
78
79 {notableMentions && (
80 <section class="notable-mentions">
81 <h3>Notable Mentions</h3>
82 { Array.isArray(notableMentions) ?
83 <ul>
84 {notableMentions.map((mention) => (
85 <li>
86 <a href={mention.url}>{mention.name}</a>
87 {mention.description && (
88 <span>- </span>
89 <span set:html={parseMarkdown(mention.description)}></span>
90 )}
91 </li>
92 ))}
93 </ul> :
94 <p set:html={parseMarkdown(notableMentions)}></p>
95 }
96 </section>
97 )}
98
99 {furtherInfo && (
100 <section class="further-info">
101 <h3>Notes</h3>
102 <p set:html={parseMarkdown(furtherInfo)}></p>
103 </section>
104 )}
105
106 {wordOfWarning && (
107 <section class="word-of-warning">
108 <h3>Word of Warning</h3>
109 <p set:html={parseMarkdown(wordOfWarning)}></p>
110 </section>
111 )}
112
113 <div class="pagination-navigation">
114 { previous ? (
115 <Button url={`/${slugify(categoryName)}/${slugify(previous)}`}>
116 <span>← Previous</span>
117 <p>{previous}</p>
118 </Button>
119 ) : <p class="nothing"></p>}
120 <a href={`/${slugify(categoryName)}`} class="go-to-category">
121 View all in {categoryName} ({otherSections.length})
122 </a>
123 { next && (
124 <Button url={`/${slugify(categoryName)}/${slugify(next)}`}>
125 <span>Next →</span>
126 <p>{next}</p>
127 </Button>
128 )}
129 </div>
130 </Main>
56</Layout> 131</Layout>
57 132
58<style lang="scss"> 133<style lang="scss">
59 main { 134
60 margin: auto; 135section {
61 padding: 1rem; 136 padding-bottom: 1rem;
62 width: 1000px; 137 &:not(:last-child) {
63 max-width: calc(100% - 2rem); 138 border-bottom: 2px solid var(--accent-3);
64 139 }
65 font-size: 20px; 140}
66 line-height: 1.6; 141
67 } 142h2 {
143 font-size: 2rem;
144 margin: -2rem 0 2rem -2rem;
145 box-shadow: 6px 6px 0 var(--foreground);
146 background: var(--accent);
147 color: var(--accent-fg);
148 width: fit-content;
149 padding: 0.25rem 0.5rem;
150 }
151
152.pagination-navigation {
153 display: flex;
154 justify-content: space-between;
155 align-items: center;
156 padding: 1rem 0;
157 :global(.button) {
158 min-width: 120px;
159 width: fit-content;
160 padding: 0.25rem 1rem;
161 text-align: right;
162 &:first-child { text-align: left; }
163 p {
164 margin: 0;
165 font-weight: normal;
166 font-size: 1rem;
167 }
168 span {
169 font-size: 0.8rem;
170 }
171
172 }
173 .nothing {
174 width: 120px;
175 }
176 .go-to-category {
177 color: var(--foreground);
178 font-size: 0.8rem;
179 opacity: 0.5;
180 }
181}
182
183.intro {
184 font-style: italic;
185 opacity: 0.7;
186}
187
188
189.further-info, .notable-mentions, .word-of-warning {
190 h3 {
191 font-size: 1.4rem;
192 margin: 1rem 0;
193 }
194 :global(p) {
195 font-size: 0.9rem;
196 opacity: 0.7;
197 :global(strong) {
198 font-weight: 500;
199 }
200 :global(a) {
201 color: var(--foreground);
202 transition: all 0.15s ease-in-out;
203 &:hover {
204 color: var(--accent);
205 }
206 }
207 }
208 ul {
209 list-style: circle;
210 padding-left: 1rem;
211 font-size: 0.9rem;
212 li {
213 margin-bottom: 0.25rem;
214 :global(p) {
215 display: inline;
216 }
217 }
218 }
219}
220
68</style> 221</style>
web/src/pages/[category].astro +9 −34
@@ -1,12 +1,12 @@
1--- 1---
2 2
3import Layout from '../layouts/Layout.astro'; 3import Layout from '@layouts/Layout.astro';
4import Card from '../components/Card.astro'; 4import SectionList from '@components/things/SectionList.astro';
5import Hero from '../components/Hero.astro'; 5import Main from '@components/scafold/MainCard.astro';
6 6
7import { fetchData, slugify } from '@utils/fetch-data';
7 8
8import yaml from 'js-yaml'; 9import type { Section } from '../types/Service';
9import type { AwesomePrivacy, Section, Service } from '../types/Service';
10 10
11interface Props { 11interface Props {
12 title: string; 12 title: string;
@@ -16,16 +16,6 @@ interface Props {
16const { title, sections } = Astro.props; 16const { title, sections } = Astro.props;
17 17
18export async function getStaticPaths() { 18export async function getStaticPaths() {
19 const fetchData = async (): Promise<AwesomePrivacy> => {
20 return await fetch('http://localhost:4321/awesome-privacy.yml')
21 .then((res) => res.text())
22 .then((data) => yaml.load(data))
23 .catch((err) => console.error(err));
24 };
25
26 const slugify = (title: string) => {
27 return title.toLowerCase().replace(/\s/g, '-');
28 };
29 19
30 const pages = await fetchData().then((data) => { 20 const pages = await fetchData().then((data) => {
31 return data.categories.map((category) => { 21 return data.categories.map((category) => {
@@ -45,29 +35,14 @@ export async function getStaticPaths() {
45 }); 35 });
46} 36}
47 37
48
49--- 38---
50 39
51<Layout title="Awesome Privacy"> 40<Layout title="Awesome Privacy">
52 <!-- <Hero /> --> 41 <Main>
53 <main> 42 <SectionList title={title} sections={sections} bigTitle={true} />
54 <h1>Title: {title}</h1> 43 </Main>
55 <!-- {sections.map((section) => (
56 <section>
57 <h2>{section.name}</h2>
58 </section>
59 ))} -->
60 </main>
61</Layout> 44</Layout>
62 45
63<style lang="scss"> 46<style lang="scss">
64 main { 47
65 margin: auto;
66 padding: 1rem;
67 width: 1000px;
68 max-width: calc(100% - 2rem);
69 color: red;
70 font-size: 20px;
71 line-height: 1.6;
72 }
73</style> 48</style>
web/src/pages/category/index.astro +3 −3
@@ -2,9 +2,9 @@
2 2
3import yaml from 'js-yaml'; 3import yaml from 'js-yaml';
4 4
5import Layout from '../../layouts/Layout.astro'; 5import Layout from '@layouts/Layout.astro';
6import Card from '../../components/Card.astro'; 6import Card from '@components/Card.astro';
7import Hero from '../../components/Hero.astro'; 7import Hero from '@components/Hero.astro';
8import { AwesomePrivacy, Section, Service } from '../../types/Service'; 8import { AwesomePrivacy, Section, Service } from '../../types/Service';
9 9
10 10
web/src/pages/index.astro +76 −8
@@ -1,15 +1,34 @@
1--- 1---
2 2
3import Layout from '../layouts/Layout.astro'; 3import Layout from '@layouts/Layout.astro';
4import Card from '../components/Card.astro'; 4import Card from '@components/Card.astro';
5import Hero from '../components/Hero.astro'; 5import Hero from '@components/Hero.astro';
6import Search from '@components/Search.astro';
7import SectionList from '@components/things/SectionList.astro';
8
9import { fetchData } from '@utils/fetch-data';
10import Button from '@components/form/Button.astro';
11
12const categories = (await fetchData()).categories;
6 13
7--- 14---
8 15
9<Layout title="Awesome Privacy"> 16<Layout title="Awesome Privacy" hideNav={true}>
10 <Hero /> 17 <Hero />
11 <main> 18 <main>
12 <Card title="Email" body="" href="/" /> 19 <h2>Search</h2>
20 <Search />
21 <h2 class="browse-title">Browse</h2>
22 <ul class="categories">
23 {categories.map((category) => (
24 <li class="category">
25 <SectionList title={category.name} sections={category.sections} />
26 </li>
27 ))}
28 </ul>
29 <div class="view-all">
30 <Button url="/all" text="View All" />
31 </div>
13 </main> 32 </main>
14</Layout> 33</Layout>
15 34
@@ -17,10 +36,59 @@ import Hero from '../components/Hero.astro';
17 main { 36 main {
18 margin: auto; 37 margin: auto;
19 padding: 1rem; 38 padding: 1rem;
20 width: 1000px; 39 width: 1100px;
21 max-width: calc(100% - 2rem); 40 max-width: calc(100% - 2rem);
22 color: white;
23 font-size: 20px; 41 font-size: 20px;
24 line-height: 1.6; 42 line-height: 1.6;
25 } 43 .view-all {
44 width: 8rem;
45 margin: 0 auto;
46 }
47 }
48 h2 {
49 font-size: 2.5rem;
50 color: var(--accent-3);
51 font-family: "Lekton", sans-serif;
52 text-align: center;
53 }
54
55 .categories {
56 columns: 6 300px;
57 column-gap: 1rem;
58 .category {
59 background: var(--accent-fg);
60 border: 2px solid var(--foreground);
61 border-radius: var(--curve-sm);
62 box-shadow: 4px 4px 0 var(--foreground);
63 padding: 1rem;
64 width: 85%;
65 display: inline-flex;
66 flex-direction: column;
67 margin: 1rem;
68 .category-title {
69 text-decoration: none;
70 color: var(--foreground);
71 }
72 h3 {
73 font-family: "Lekton", sans-serif;
74 font-weight: bold;
75 margin: 0;
76 font-size: 1.8rem;
77 }
78 .sections {
79 padding-left: 1rem;
80 .section {
81 a {
82 text-decoration: none;
83 color: var(--foreground);
84 }
85 .service-count {
86 color: var(--accent-3);
87 }
88 }
89 }
90 }
91 }
92
93
26</style> 94</style>