// Blog list + blog post
function BlogPage() {
const { go } = CTSCShell.useNav();
const { data } = CTSCStore.useStore();
const { fmtDate } = CTSCStore;
const { Photo, Avatar } = CTSCShell;
const [cat, setCat] = React.useState('All');
const approved = [...(data.blog || [])].filter(b => b.status === 'Approved').sort((a, b) => b.date.localeCompare(a.date));
const cats = ['All', ...Array.from(new Set(approved.map(b => b.category)))];
const list = approved.filter(b => cat === 'All' || b.category === cat);
const [feat, ...rest] = list;
return (
The CTSC Blog
Stories from Cape sport
Spotlights, behind-the-scenes, history and the fun side of sport in the Mother City.
{cats.map(c => )}
{feat && (
)}
{rest.map(b => (
))}
{list.length === 0 &&
No posts in this category yet.
}
);
}
function BlogPost({ id }) {
const { go } = CTSCShell.useNav();
const { data } = CTSCStore.useStore();
const { fmtDate } = CTSCStore;
const { Photo, Avatar } = CTSCShell;
const b = (data.blog || []).find(x => x.id === id);
if (!b) return ;
const more = (data.blog || []).filter(x => x.status === 'Approved' && x.id !== id).slice(0, 3);
return (
{b.category} · {fmtDate(b.date)}
{b.title}
{b.author}
Cape Town Sport Council
{b.excerpt}
{b.body}
{more.length > 0 && (
More from the blog
{more.map(p => (
))}
)}
);
}
window.BlogPage = BlogPage;
window.BlogPost = BlogPost;