From 6d59aa8201a1fd3abea32ef36206af6471d85435 Mon Sep 17 00:00:00 2001 From: Emile Bangma Date: Fri, 8 Mar 2024 10:04:44 +0100 Subject: [PATCH] fix(description): counts characters instead of words (#972) * fix(description): make sure description counts characters instead of words * ref: removed duplicate ternary --- quartz/plugins/transformers/description.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/quartz/plugins/transformers/description.ts b/quartz/plugins/transformers/description.ts index b582fee..2ec8880 100644 --- a/quartz/plugins/transformers/description.ts +++ b/quartz/plugins/transformers/description.ts @@ -42,22 +42,25 @@ export const Description: QuartzTransformerPlugin | undefined> 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.push(sentence) + currentDescriptionLength += sentence.length sentenceIdx++ } finalDesc.push("...") } else { - while (finalDesc.length < len) { + while (currentDescriptionLength < len) { const sentence = sentences[sentenceIdx] if (!sentence) break - finalDesc.push(sentence.endsWith(".") ? sentence : sentence + ".") - sentenceIdx++ + const currentSentence = sentence.endsWith(".") ? sentence : sentence + "." + finalDesc.push(currentSentence) + currentDescriptionLength += currentSentence.length } }