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 @@
11---
22
3import yaml from 'js-yaml';
43
5import Layout from '../layouts/Layout.astro';
6import Card from '../components/Card.astro';
7import Hero from '../components/Hero.astro';
8import { AwesomePrivacy, Section, Service } from '../types/Service';
4import Layout from '@layouts/Layout.astro';
5import Button from '@components/form/Button.astro';
6import Main from '@components/scafold/MainCard.astro';
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}
923
10const { title, otherSections, services } = Astro.props;
24const { slug, title, otherSections, services, notableMentions, furtherInfo, wordOfWarning, categoryName, intro } = Astro.props;
1125
1226export async function getStaticPaths() {
1327
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
2728const pages = await fetchData().then((data) => {
28
29 const results: { slug: string, title: string, otherSections: Section[], services: Service[] }[] = [];
30 data.categories.forEach((service) => {
31 const sections = service.sections.map((section) => ({
32 slug: `${slugify(service.name)}/${slugify(section.name)}`,
29 const results: Array<Props> = [];
30 (data as AwesomePrivacy).categories.forEach((category) => {
31 const sections = category.sections.map((section) => ({
32 slug: `${slugify(category.name)}/${slugify(section.name)}`,
3333 title: section.name,
3434 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,
3641 }));
3742 results.push(...sections);
3843 });
3944 return results;
4045});
4146
42return pages.map(({ slug, title, otherSections, services }) => {
47return pages.map(({ slug, title, otherSections, services, notableMentions, furtherInfo, wordOfWarning, categoryName, intro }) => {
4348 return {
4449 params: { section: slug },
45 props: { title, otherSections, services },
50 props: { title, otherSections, services, notableMentions, furtherInfo, wordOfWarning, categoryName, intro },
4651 };
4752});
48
4953}
5054
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
5164---
5265
5366<Layout title="Awesome Privacy">
54
55 <h1>{title}</h1>
67 <Main>
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>
56131</Layout>
57132
58133<style lang="scss">
59 main {
60 margin: auto;
61 padding: 1rem;
62 width: 1000px;
63 max-width: calc(100% - 2rem);
64
65 font-size: 20px;
66 line-height: 1.6;
67 }
134
135section {
136 padding-bottom: 1rem;
137 &:not(:last-child) {
138 border-bottom: 2px solid var(--accent-3);
139 }
140}
141
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
68221</style>
web/src/pages/[category].astro +9 −34
@@ -1,12 +1,12 @@
11---
22
3import Layout from '../layouts/Layout.astro';
4import Card from '../components/Card.astro';
5import Hero from '../components/Hero.astro';
3import Layout from '@layouts/Layout.astro';
4import SectionList from '@components/things/SectionList.astro';
5import Main from '@components/scafold/MainCard.astro';
66
7import { fetchData, slugify } from '@utils/fetch-data';
78
8import yaml from 'js-yaml';
9import type { AwesomePrivacy, Section, Service } from '../types/Service';
9import type { Section } from '../types/Service';
1010
1111interface Props {
1212 title: string;
@@ -16,16 +16,6 @@ interface Props {
1616const { title, sections } = Astro.props;
1717
1818export 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 };
2919
3020 const pages = await fetchData().then((data) => {
3121 return data.categories.map((category) => {
@@ -45,29 +35,14 @@ export async function getStaticPaths() {
4535 });
4636}
4737
48
4938---
5039
5140<Layout title="Awesome Privacy">
52 <!-- <Hero /> -->
53 <main>
54 <h1>Title: {title}</h1>
55 <!-- {sections.map((section) => (
56 <section>
57 <h2>{section.name}</h2>
58 </section>
59 ))} -->
60 </main>
41 <Main>
42 <SectionList title={title} sections={sections} bigTitle={true} />
43 </Main>
6144</Layout>
6245
6346<style lang="scss">
64 main {
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 }
47
7348</style>
web/src/pages/category/index.astro +3 −3
@@ -2,9 +2,9 @@
22
33import yaml from 'js-yaml';
44
5import Layout from '../../layouts/Layout.astro';
6import Card from '../../components/Card.astro';
7import Hero from '../../components/Hero.astro';
5import Layout from '@layouts/Layout.astro';
6import Card from '@components/Card.astro';
7import Hero from '@components/Hero.astro';
88import { AwesomePrivacy, Section, Service } from '../../types/Service';
99
1010
web/src/pages/index.astro +76 −8
@@ -1,15 +1,34 @@
11---
22
3import Layout from '../layouts/Layout.astro';
4import Card from '../components/Card.astro';
5import Hero from '../components/Hero.astro';
3import Layout from '@layouts/Layout.astro';
4import Card from '@components/Card.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;
613
714---
815
9<Layout title="Awesome Privacy">
16<Layout title="Awesome Privacy" hideNav={true}>
1017 <Hero />
1118 <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>
1332 </main>
1433</Layout>
1534
@@ -17,10 +36,59 @@ import Hero from '../components/Hero.astro';
1736 main {
1837 margin: auto;
1938 padding: 1rem;
20 width: 1000px;
39 width: 1100px;
2140 max-width: calc(100% - 2rem);
22 color: white;
2341 font-size: 20px;
2442 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
2694</style>