Skip to content

Commit 64b120e

Browse files
committed
fix: SAFARI REGEX BACK AT IT AGAIN
1 parent a1d830e commit 64b120e

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

apps/trialanderror.org/src/app/Card.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,22 @@ import Link from 'next/link'
55
import { motion } from 'framer-motion'
66
import { format } from 'date-fns'
77

8+
function splitSentences(sentence: string) {
9+
const regex = /[^.!?]+[.!?]/g
10+
const matches = sentence.match(regex)
11+
return matches ? matches.map((s) => s.trim()) : [sentence]
12+
}
13+
814
export function Card({ card, delay = 0 }: { card: Card; delay?: number }) {
915
const { title, image, url, excerpt, team, published, type, category, id } = card
1016

1117
// split the title by colons, periods, and exclamation points
1218
// make the first part of the title the main title
1319
// make the rest of the title the subtitle
1420

15-
const titleParts = title.split(/(?<=([:.?!])) /)
16-
const mainTitle = titleParts[0]?.replace(/[:.]/g, '')
17-
const subTitle = titleParts.slice(1).join(' ')?.replace(/[:.]/g, '').trim()
21+
const titleParts = /(.*?[?.:!])(.*)/g.exec(title) ?? [title, title, '']
22+
const mainTitle = titleParts[1]?.replace(/[:.]/g, '')
23+
const subTitle = titleParts.slice(2).join(' ')?.replace(/[:.]/g, '').trim()
1824
const capitalizedSubTitle = subTitle.charAt(0).toUpperCase() + subTitle.slice(1)
1925
const titleClass = subTitle ? 'text-2xl' : 'text-3xl'
2026

0 commit comments

Comments
 (0)