| | |
| | | |
| | | const desc = frontMatterDescription ?? text |
| | | const sentences = desc.replace(/\s+/g, " ").split(/\.\s/) |
| | | let finalDesc = "" |
| | | let sentenceIdx = 0 |
| | | const finalDesc: string[] = [] |
| | | const len = opts.descriptionLength |
| | | let sentenceIdx = 0 |
| | | let currentDescriptionLength = 0 |
| | | |
| | | if (sentences[0] !== undefined && sentences[0].length >= len) { |
| | | const firstSentence = sentences[0].split(" ") |
| | | while (finalDesc.length < len) { |
| | | while (currentDescriptionLength < len) { |
| | | const sentence = firstSentence[sentenceIdx] |
| | | if (!sentence) break |
| | | finalDesc += sentence + " " |
| | | finalDesc.push(sentence) |
| | | currentDescriptionLength += sentence.length |
| | | sentenceIdx++ |
| | | } |
| | | finalDesc = finalDesc.trimEnd() + "..." |
| | | finalDesc.push("...") |
| | | } else { |
| | | while (finalDesc.length < len) { |
| | | while (currentDescriptionLength < len) { |
| | | const sentence = sentences[sentenceIdx] |
| | | if (!sentence) break |
| | | finalDesc += sentence.endsWith(".") ? sentence : sentence + "." |
| | | sentenceIdx++ |
| | | const currentSentence = sentence.endsWith(".") ? sentence : sentence + "." |
| | | finalDesc.push(currentSentence) |
| | | currentDescriptionLength += currentSentence.length |
| | | } |
| | | } |
| | | |
| | | file.data.description = finalDesc |
| | | file.data.description = finalDesc.join(" ") |
| | | file.data.text = text |
| | | } |
| | | }, |