diff --git a/src/components/RecentlyFromTheCouncil.astro b/src/components/RecentlyFromTheCouncil.astro new file mode 100644 index 0000000..16b1294 --- /dev/null +++ b/src/components/RecentlyFromTheCouncil.astro @@ -0,0 +1,123 @@ +--- +import Avatar from './Avatar.astro'; +import { getContributions } from '../lib/db'; +import { relativeTime, stripMarkdownLight } from '../lib/format'; + +const [latest] = getContributions({ sort: 'newest' }); + +const TYPE_LABEL = { idea: 'Idea', inspiration: 'Inspiration', question: 'Question' } as const; +const TYPE_PIGMENT = { + idea: 'var(--pigment-copper)', + inspiration: 'var(--pigment-ochre)', + question: 'var(--pigment-indigo)', +} as const; + +function trimQuote(body: string, max = 220): string { + const stripped = stripMarkdownLight(body); + if (stripped.length <= max) return stripped; + const cut = stripped.slice(0, max); + const last = Math.max(cut.lastIndexOf(' '), cut.lastIndexOf('.')); + return (last > max - 40 ? cut.slice(0, last) : cut).trim() + '…'; +} +--- +{latest && ( +
+
+

Recently from the council

+ All contributions → +
+ +
+ + {latest.author_name} + {relativeTime(latest.created_at)} + {TYPE_LABEL[latest.type]} +
+ +
{trimQuote(latest.body_md)}
+ +

+ {latest.reaction_count === 0 + ? 'No reactions yet' + : `${latest.reaction_count} reaction${latest.reaction_count === 1 ? '' : 's'} from the council`} +

+
+)} + +