diff --git a/src/components/Post.astro b/src/components/Post.astro index 1278cfd..20c19e7 100644 --- a/src/components/Post.astro +++ b/src/components/Post.astro @@ -17,7 +17,7 @@ const { slug, title, tags, description, date } = Astro.props; diff --git a/src/pages/tag/[tag].astro b/src/pages/tag/[tag].astro new file mode 100644 index 0000000..49e6b47 --- /dev/null +++ b/src/pages/tag/[tag].astro @@ -0,0 +1,86 @@ +--- +import BaseHead from '../../components/BaseHead.astro'; +import Header from '../../components/Header.astro'; +import Footer from '../../components/Footer.astro'; +import Post from '../../components/Post.astro'; + +import { SITE_TITLE, SITE_DESCRIPTION } from '../../config'; + +// @rachsmithcodes wrote this +function postTags(posts) { + return posts.reduce((allTags, post) => { + const postTags = post.frontmatter.tags; + if (postTags) { + postTags.forEach((tag) => { + if (!allTags[tag]) { + allTags[tag] = []; + } + allTags[tag].push(post); + }); + } + return allTags; + }, {}); +} + +// Credit to @rachsmithcodes for helping out my lil ol brain +export async function getStaticPaths() { + let posts = await Astro.glob(`../../posts/*.md`); + const tags = posts.reduce((allTags, post) => { + const postTags = post.frontmatter.tags; + if (postTags) { + postTags.forEach((tag) => { + if (!allTags[tag]) { + allTags[tag] = []; + } + allTags[tag].push(post); + }); + } + return allTags; + }, {}); + + console.log(tags) + + return Object.keys(tags).map((t) => { + return ({ + params: { tag: t }, + props: { tag: tags[t] }, + }) + }); +} + +const { tag } = Astro.props; + +--- + + + + + + + + +
+
+ +
    + {tag.map( + ({url, frontmatter: { description, slug, title, tags, added: date }}) => ( + + ))} +
+
+
+ +