import { JSDOM } from "jsdom";

export function getDesc180(content: string) {
  let result = "";
  if (content) {
    const dom = new JSDOM(content);
    const document = dom.window.document;
    const paragraphs = document.querySelectorAll("p");

    let combinedText = "";
    paragraphs.forEach((p) => {
      combinedText += p.textContent?.trim() || "";
    });

    result = combinedText.slice(0, 180);
  }
  return result;
}

export function getDescLast(content: string) {
  let result = "";
  if (content) {
    const dom = new JSDOM(content);
    const paragraphs = dom.window.document.querySelectorAll("p");

    if (paragraphs.length > 0) {
      result = paragraphs[paragraphs.length - 1].textContent?.trim() || "";
    }
  }
  return result;
}
