🔗 added RSS link
This commit is contained in:
parent
f44f06b949
commit
7db707e838
1 changed files with 5 additions and 3 deletions
|
@ -2,13 +2,14 @@
|
||||||
import { getCollection } from 'astro:content';
|
import { getCollection } from 'astro:content';
|
||||||
import FormattedDate from '../../components/FormattedDate.astro';
|
import FormattedDate from '../../components/FormattedDate.astro';
|
||||||
import SectionContainer from '../../components/SectionContainer.astro';
|
import SectionContainer from '../../components/SectionContainer.astro';
|
||||||
|
import BaseHead from '../../components/BaseHead.astro';
|
||||||
|
|
||||||
const posts = (await getCollection('blog')).sort(
|
const posts = (await getCollection('blog')).sort(
|
||||||
(a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf()
|
(a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Group posts by year
|
// Group posts by year
|
||||||
const postsByYear = posts.reduce((acc, post) => {
|
const postsByYear = posts.reduce((acc:any, post) => {
|
||||||
const year = new Date(post.data.pubDate).getFullYear();
|
const year = new Date(post.data.pubDate).getFullYear();
|
||||||
if (!acc[year]) {
|
if (!acc[year]) {
|
||||||
acc[year] = [];
|
acc[year] = [];
|
||||||
|
@ -18,17 +19,18 @@ const postsByYear = posts.reduce((acc, post) => {
|
||||||
}, {});
|
}, {});
|
||||||
|
|
||||||
// Sort the years
|
// Sort the years
|
||||||
const sortedYears = Object.keys(postsByYear).sort((a, b) => b - a);
|
const sortedYears = Object.keys(postsByYear).sort((a:any, b:any) => b - a);
|
||||||
---
|
---
|
||||||
<SectionContainer>
|
<SectionContainer>
|
||||||
<main class="flex flex-col h-screen gap-4 mt-4">
|
<main class="flex flex-col h-screen gap-4 mt-4">
|
||||||
<h1 class="text-3xl font-extrabold">Blog posts</h1>
|
<h1 class="text-3xl font-extrabold">Blog posts</h1>
|
||||||
|
<a href="/rss.xml">💥 Subscribe via RSS</a>
|
||||||
{sortedYears.map(year => (
|
{sortedYears.map(year => (
|
||||||
<section>
|
<section>
|
||||||
<div class="text-xl font-semibold">{year}</div>
|
<div class="text-xl font-semibold">{year}</div>
|
||||||
<ul>
|
<ul>
|
||||||
{
|
{
|
||||||
postsByYear[year].map((post) => (
|
postsByYear[year].map((post:any) => (
|
||||||
<div class="flex justify-between mb-2 break-words">
|
<div class="flex justify-between mb-2 break-words">
|
||||||
<a class="font-semibold" href={`/blog/${post.slug}/`}>✨ {post.data.title}</a>
|
<a class="font-semibold" href={`/blog/${post.slug}/`}>✨ {post.data.title}</a>
|
||||||
<FormattedDate date={post.data.pubDate} />
|
<FormattedDate date={post.data.pubDate} />
|
||||||
|
|
Loading…
Add table
Reference in a new issue