Files
petfeed/src/lib/parse-caption.ts
T
admin 2568c32cf4 feat: notification polling 30s->10s, video thumbnails, @-mentions
- NotificationBell: refetchInterval 30000->10000, refetchOnWindowFocus, i18n label
- ProfileTabs: Mux thumbnail for VIDEO posts in grid, play icon overlay
- parse-caption: add mention segment type for @word parsing
- MentionTextarea: new component with @-autocomplete via search.pets
- PostCard: render @mentions as blue links to /search
- CommentSheet: parse comment bodies for mentions, use MentionTextarea
- PhotoPostForm: use MentionTextarea for caption input
2026-06-23 06:17:58 +02:00

20 lines
650 B
TypeScript

export type CaptionSegment =
| { type: "text"; text: string }
| { type: "hashtag"; tag: string }
| { type: "mention"; name: string };
export function parseCaption(caption: string): CaptionSegment[] {
const segments: CaptionSegment[] = [];
const parts = caption.split(/(#\w{1,50}|@\w{1,50})/g);
for (const part of parts) {
if (part.startsWith("#")) {
segments.push({ type: "hashtag", tag: part.slice(1).toLowerCase() });
} else if (part.startsWith("@")) {
segments.push({ type: "mention", name: part.slice(1) });
} else if (part) {
segments.push({ type: "text", text: part });
}
}
return segments;
}