/** * 게시물 요약 또는 본문에서 목록·메타용 짧은 텍스트를 만든다. * @param {string} excerpt - 게시물 요약 * @param {string} content - 게시물 본문(마크다운) * @param {Object} [options] - 옵션 * @param {number} [options.maxLength=160] - 최대 글자 수 * @param {boolean} [options.appendEllipsis=true] - 잘린 문자열 끝에 말줄임 추가 여부 * @returns {string} 화면 표시용 요약 */ export function createPostSummary(excerpt = '', content = '', options = {}) { const maxLength = Number(options.maxLength) > 0 ? Number(options.maxLength) : 160 const appendEllipsis = options.appendEllipsis !== false const source = String(excerpt || '').trim() || String(content || '') const plainText = source .replace(/```[\s\S]*?```/g, ' ') .replace(/:::[\s\S]*?:::/g, ' ') .replace(//g, ' ') .replace(/!\[[^\]]*]\([^)]*\)/g, ' ') .replace(/\[([^\]]+)]\([^)]*\)/g, '$1') .replace(/https?:\/\/\S+/g, ' ') .replace(/[#>*_`~|-]+/g, ' ') .replace(/\s+/g, ' ') .trim() if (!plainText) { return '' } if (plainText.length <= maxLength) { return plainText } if (!appendEllipsis) { return plainText.slice(0, maxLength).trim() } return `${plainText.slice(0, maxLength - 3).trim()}...` }