export function getFirstWordsFromFirstPOrDiv(htmlString) {
  const parser = new DOMParser();
  const doc = parser.parseFromString(htmlString, "text/html");

  let content = "";

  // Try <p> first
  const firstP = doc.querySelector("p");
  if (firstP && firstP?.textContent?.trim()) {
    content = firstP.textContent.trim();
  } else {
    // Fallback to first <div> with text
    const divs = doc.querySelectorAll("div");
    for (const div of divs) {
      if (div?.textContent?.trim()) {
        content = div.textContent.trim();
        break;
      }
    }
  }

  const words = content.split(/\s+/);
  const first200 = words.slice(0, 200).join(" ");
  return first200;
}
