diff options
| author | Joe Carstairs <65492573+joeacarstairs@users.noreply.github.com> | 2024-05-05 21:00:40 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-05 21:00:40 +0100 |
| commit | 86450b3dd8bec3b76e2b2a03b8cdc8a708c5f3bc (patch) | |
| tree | 7576d8863193369adc87dd80d91a3d5d3f58ede1 /website/src/components/BlogFeed.astro | |
| parent | 579e12cfebce9a70ab2adf5842e2673673a707d2 (diff) | |
Infrastructure as code (#3)
* Moves website to website/
* Adds terraform gitignores
* Terraform with AWS provider
* Initialises Terraform
* Locals and variables for provider
* Fetches SSL certificate from ACM
* S3 static website bucket
* CloudFront distribution
* Route53 records
* Deployment workflow uses secret S3 bucket suffix
* Adds README
---------
Co-authored-by: Joe Carstairs <65492573+Sycamost@users.noreply.github.com>
Diffstat (limited to 'website/src/components/BlogFeed.astro')
| -rw-r--r-- | website/src/components/BlogFeed.astro | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/website/src/components/BlogFeed.astro b/website/src/components/BlogFeed.astro new file mode 100644 index 0000000..b6f9d55 --- /dev/null +++ b/website/src/components/BlogFeed.astro @@ -0,0 +1,76 @@ +--- +import type { CollectionEntry } from 'astro:content'; +import { getCollection } from 'astro:content'; + +export interface Props { + headingLevel?: 1 | 2 | 3 | 4 | 5 | 6, + hideAuthor?: boolean, +}; + +const { headingLevel = 2, hideAuthor = false } = Astro.props; + +const posts = (await getCollection('blog')); + +const distinctYears: number[] = posts + .map(post => post.data.pubDate.year) + .reduce<number[]>((acc, curr) => acc.includes(curr) ? acc : [...acc, curr], []) + .sort((a, b) => b - a); + +function matchesYear(year: number) { + return (post: CollectionEntry<'blog'>) => post.data.pubDate.year === year; +} + +function sortByPubDateDescending(post1: CollectionEntry<'blog'>, post2: CollectionEntry<'blog'>) { + const year1 = post1.data.pubDate.year; + const year2 = post2.data.pubDate.year; + const month1 = post1.data.pubDate.month; + const month2 = post2.data.pubDate.month; + const day1 = post1.data.pubDate.day; + const day2 = post2.data.pubDate.day; + + if (year1 !== year2) { + return year2 - year1; + } else if (month1 !== month2) { + return month2 - month1; + } else { + return day2 - day1; + } +} + +const headingElem = `h${headingLevel}`; + +const canonicalBlogUrl = new URL('blog', Astro.site) +--- + +<section class="h-feed"> + <Fragment set:html={` + <${headingElem} class="p-name"> + My blog + </${headingElem}> + `} /> + + <aside> + <p class={hideAuthor ? 'hidden' : ''}> + This blog is written by <a class="p-author h-card" href="/">Joe Carstairs</a> + </p> + + <p> + <a class="u-url" href={canonicalBlogUrl}>Permalink</a> + </p> + </aside> + + <ul> + { distinctYears.map(year => ( + <li> + {year} + <ul> + { posts.filter(matchesYear(year)).sort(sortByPubDateDescending).map(post => ( + <li class="h-entry"> + <a class="u-url p-name" href={`/blog/${post.slug}`}>{post.data.title}</a> + </li> + )) } + </ul> + </li> + )) } + </ul> +</section>
\ No newline at end of file |
