diff --git a/web/src/pages/[...section].astro b/web/src/pages/[...section].astro index e4b4c2c..3b28eda 100644 --- a/web/src/pages/[...section].astro +++ b/web/src/pages/[...section].astro @@ -1,68 +1,221 @@ --- -import yaml from 'js-yaml'; -import Layout from '../layouts/Layout.astro'; -import Card from '../components/Card.astro'; -import Hero from '../components/Hero.astro'; -import { AwesomePrivacy, Section, Service } from '../types/Service'; +import Layout from '@layouts/Layout.astro'; +import Button from '@components/form/Button.astro'; +import Main from '@components/scafold/MainCard.astro'; +import ServiceList from '@components/things/ServiceList.astro'; +import type { AwesomePrivacy, Section, Service, ShortService } from '../types/Service'; +import { fetchData, slugify } from '@utils/fetch-data'; +import { parseMarkdown } from '@utils/parse-markdown'; -const { title, otherSections, services } = Astro.props; +interface Props { + slug: string, + title: string, + services: Service[], + intro?: string, + notableMentions?: ShortService[] | string, + furtherInfo?: string, + wordOfWarning?: string, + categoryName: string, + otherSections: Section[], +} + +const { slug, title, otherSections, services, notableMentions, furtherInfo, wordOfWarning, categoryName, intro } = Astro.props; export async function getStaticPaths() { -const fetchData = async (): Promise => { - return await fetch('http://localhost:4321/awesome-privacy.yml') - .then((res) => res.text()) - .then((data) => yaml.load(data)) - .catch((err) => console.error(err)); -}; - - -const slugify = (title: string) => { - return title.toLowerCase().replace(/\s/g, '-'); -}; - - const pages = await fetchData().then((data) => { - - const results: { slug: string, title: string, otherSections: Section[], services: Service[] }[] = []; - data.categories.forEach((service) => { - const sections = service.sections.map((section) => ({ - slug: `${slugify(service.name)}/${slugify(section.name)}`, + const results: Array = []; + (data as AwesomePrivacy).categories.forEach((category) => { + const sections = category.sections.map((section) => ({ + slug: `${slugify(category.name)}/${slugify(section.name)}`, title: section.name, services: section.services, - otherSections: service.sections, + intro: section.intro, + notableMentions: section.notableMentions, + furtherInfo: section.furtherInfo, + wordOfWarning: section.wordOfWarning, + categoryName: category.name, + otherSections: category.sections, })); results.push(...sections); }); return results; }); -return pages.map(({ slug, title, otherSections, services }) => { +return pages.map(({ slug, title, otherSections, services, notableMentions, furtherInfo, wordOfWarning, categoryName, intro }) => { return { params: { section: slug }, - props: { title, otherSections, services }, + props: { title, otherSections, services, notableMentions, furtherInfo, wordOfWarning, categoryName, intro }, }; }); - } +const makePaginationLinks = () => { + const index = otherSections.findIndex(section => section.name === title); + const previousSection = index > 0 ? otherSections[index - 1].name : null; + const nextSection = index < otherSections.length - 1 ? otherSections[index + 1].name : null; + return { previous: previousSection, next: nextSection }; +}; + +const { previous, next } = makePaginationLinks(); + --- +
-

{title}

+

{title}

+ + {intro && ( +
+

+
+ )} + + + + {notableMentions && ( +
+

Notable Mentions

+ { Array.isArray(notableMentions) ? +
    + {notableMentions.map((mention) => ( +
  • + {mention.name} + {mention.description && ( + - + + )} +
  • + ))} +
: +

+ } +
+ )} + + {furtherInfo && ( +
+

Notes

+

+
+ )} + + {wordOfWarning && ( +
+

Word of Warning

+

+
+ )} + +
+ { previous ? ( + + ) :

} + + View all in {categoryName} ({otherSections.length}) + + { next && ( + + )} +
+
diff --git a/web/src/pages/[category].astro b/web/src/pages/[category].astro index 9cf6d60..6f97af2 100644 --- a/web/src/pages/[category].astro +++ b/web/src/pages/[category].astro @@ -1,12 +1,12 @@ --- -import Layout from '../layouts/Layout.astro'; -import Card from '../components/Card.astro'; -import Hero from '../components/Hero.astro'; +import Layout from '@layouts/Layout.astro'; +import SectionList from '@components/things/SectionList.astro'; +import Main from '@components/scafold/MainCard.astro'; +import { fetchData, slugify } from '@utils/fetch-data'; -import yaml from 'js-yaml'; -import type { AwesomePrivacy, Section, Service } from '../types/Service'; +import type { Section } from '../types/Service'; interface Props { title: string; @@ -16,16 +16,6 @@ interface Props { const { title, sections } = Astro.props; export async function getStaticPaths() { - const fetchData = async (): Promise => { - return await fetch('http://localhost:4321/awesome-privacy.yml') - .then((res) => res.text()) - .then((data) => yaml.load(data)) - .catch((err) => console.error(err)); - }; - - const slugify = (title: string) => { - return title.toLowerCase().replace(/\s/g, '-'); - }; const pages = await fetchData().then((data) => { return data.categories.map((category) => { @@ -45,29 +35,14 @@ export async function getStaticPaths() { }); } - --- - -
-

Title: {title}

- -
+
+ +
diff --git a/web/src/pages/category/index.astro b/web/src/pages/category/index.astro index 0ffe022..2535a63 100644 --- a/web/src/pages/category/index.astro +++ b/web/src/pages/category/index.astro @@ -2,9 +2,9 @@ import yaml from 'js-yaml'; -import Layout from '../../layouts/Layout.astro'; -import Card from '../../components/Card.astro'; -import Hero from '../../components/Hero.astro'; +import Layout from '@layouts/Layout.astro'; +import Card from '@components/Card.astro'; +import Hero from '@components/Hero.astro'; import { AwesomePrivacy, Section, Service } from '../../types/Service'; diff --git a/web/src/pages/index.astro b/web/src/pages/index.astro index 5cf4bc5..fda7b3a 100644 --- a/web/src/pages/index.astro +++ b/web/src/pages/index.astro @@ -1,15 +1,34 @@ --- -import Layout from '../layouts/Layout.astro'; -import Card from '../components/Card.astro'; -import Hero from '../components/Hero.astro'; +import Layout from '@layouts/Layout.astro'; +import Card from '@components/Card.astro'; +import Hero from '@components/Hero.astro'; +import Search from '@components/Search.astro'; +import SectionList from '@components/things/SectionList.astro'; + +import { fetchData } from '@utils/fetch-data'; +import Button from '@components/form/Button.astro'; + +const categories = (await fetchData()).categories; --- - +
- +

Search

+ +

Browse

+
    + {categories.map((category) => ( +
  • + +
  • + ))} +
+
+
@@ -17,10 +36,59 @@ import Hero from '../components/Hero.astro'; main { margin: auto; padding: 1rem; - width: 1000px; + width: 1100px; max-width: calc(100% - 2rem); - color: white; font-size: 20px; line-height: 1.6; - } + .view-all { + width: 8rem; + margin: 0 auto; + } + } + h2 { + font-size: 2.5rem; + color: var(--accent-3); + font-family: "Lekton", sans-serif; + text-align: center; + } + + .categories { + columns: 6 300px; + column-gap: 1rem; + .category { + background: var(--accent-fg); + border: 2px solid var(--foreground); + border-radius: var(--curve-sm); + box-shadow: 4px 4px 0 var(--foreground); + padding: 1rem; + width: 85%; + display: inline-flex; + flex-direction: column; + margin: 1rem; + .category-title { + text-decoration: none; + color: var(--foreground); + } + h3 { + font-family: "Lekton", sans-serif; + font-weight: bold; + margin: 0; + font-size: 1.8rem; + } + .sections { + padding-left: 1rem; + .section { + a { + text-decoration: none; + color: var(--foreground); + } + .service-count { + color: var(--accent-3); + } + } + } + } + } + +