From 141dd3b51f59aabc8ef3506d040f7360a86f26d0 Mon Sep 17 00:00:00 2001 From: Aaron Pham <29749331+aarnphm@users.noreply.github.com> Date: Wed, 6 Mar 2024 22:45:02 -0500 Subject: [PATCH] fix(description): make sure to we join space correctly (#970) Signed-off-by: Aaron <29749331+aarnphm@users.noreply.github.com> --- quartz/plugins/transformers/description.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/quartz/plugins/transformers/description.ts b/quartz/plugins/transformers/description.ts index 0f8cd8d3..b582feea 100644 --- a/quartz/plugins/transformers/description.ts +++ b/quartz/plugins/transformers/description.ts @@ -39,29 +39,29 @@ export const Description: QuartzTransformerPlugin | undefined> 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 if (sentences[0] !== undefined && sentences[0].length >= len) { const firstSentence = sentences[0].split(" ") while (finalDesc.length < len) { const sentence = firstSentence[sentenceIdx] if (!sentence) break - finalDesc += sentence + " " + finalDesc.push(sentence) sentenceIdx++ } - finalDesc = finalDesc.trimEnd() + "..." + finalDesc.push("...") } else { while (finalDesc.length < len) { const sentence = sentences[sentenceIdx] if (!sentence) break - finalDesc += sentence.endsWith(".") ? sentence : sentence + "." + finalDesc.push(sentence.endsWith(".") ? sentence : sentence + ".") sentenceIdx++ } } - file.data.description = finalDesc + file.data.description = finalDesc.join(" ") file.data.text = text } },