| @@ -1,68 +1,221 @@ |
| 1 | 1 | --- |
| 2 | 2 | |
| 3 | | import yaml from 'js-yaml'; |
| 4 | 3 | |
| 5 | | import Layout from '../layouts/Layout.astro'; |
| 6 | | import Card from '../components/Card.astro'; |
| 7 | | import Hero from '../components/Hero.astro'; |
| 8 | | import { AwesomePrivacy, Section, Service } from '../types/Service'; |
| 4 | import Layout from '@layouts/Layout.astro'; |
| 5 | import Button from '@components/form/Button.astro'; |
| 6 | import Main from '@components/scafold/MainCard.astro'; |
| 7 | import ServiceList from '@components/things/ServiceList.astro'; |
| 8 | import type { AwesomePrivacy, Section, Service, ShortService } from '../types/Service'; |
| 9 | import { fetchData, slugify } from '@utils/fetch-data'; |
| 10 | import { parseMarkdown } from '@utils/parse-markdown'; |
| 11 | |
| 12 | interface 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 | |
| 10 | | const { title, otherSections, services } = Astro.props; |
| 24 | const { slug, title, otherSections, services, notableMentions, furtherInfo, wordOfWarning, categoryName, intro } = Astro.props; |
| 11 | 25 | |
| 12 | 26 | export async function getStaticPaths() { |
| 13 | 27 | |
| 14 | | const 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 | | |
| 22 | | const slugify = (title: string) => { |
| 23 | | return title.toLowerCase().replace(/\s/g, '-'); |
| 24 | | }; |
| 25 | | |
| 26 | | |
| 27 | 28 | const 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)}`, |
| 33 | 33 | title: section.name, |
| 34 | 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 | 42 | results.push(...sections); |
| 38 | 43 | }); |
| 39 | 44 | return results; |
| 40 | 45 | }); |
| 41 | 46 | |
| 42 | | return pages.map(({ slug, title, otherSections, services }) => { |
| 47 | return pages.map(({ slug, title, otherSections, services, notableMentions, furtherInfo, wordOfWarning, categoryName, intro }) => { |
| 43 | 48 | return { |
| 44 | 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 | |
| 55 | const 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 | |
| 62 | const { previous, next } = makePaginationLinks(); |
| 63 | |
| 51 | 64 | --- |
| 52 | 65 | |
| 53 | 66 | <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> |
| 56 | 131 | </Layout> |
| 57 | 132 | |
| 58 | 133 | <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 | |
| 135 | section { |
| 136 | padding-bottom: 1rem; |
| 137 | &:not(:last-child) { |
| 138 | border-bottom: 2px solid var(--accent-3); |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | h2 { |
| 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 | 221 | </style> |