fix(description): counts characters instead of words (#972)
* fix(description): make sure description counts characters instead of words * ref: removed duplicate ternary
This commit is contained in:
		@@ -42,22 +42,25 @@ export const Description: QuartzTransformerPlugin<Partial<Options> | undefined>
 | 
				
			|||||||
            const finalDesc: string[] = []
 | 
					            const finalDesc: string[] = []
 | 
				
			||||||
            const len = opts.descriptionLength
 | 
					            const len = opts.descriptionLength
 | 
				
			||||||
            let sentenceIdx = 0
 | 
					            let sentenceIdx = 0
 | 
				
			||||||
 | 
					            let currentDescriptionLength = 0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (sentences[0] !== undefined && sentences[0].length >= len) {
 | 
					            if (sentences[0] !== undefined && sentences[0].length >= len) {
 | 
				
			||||||
              const firstSentence = sentences[0].split(" ")
 | 
					              const firstSentence = sentences[0].split(" ")
 | 
				
			||||||
              while (finalDesc.length < len) {
 | 
					              while (currentDescriptionLength < len) {
 | 
				
			||||||
                const sentence = firstSentence[sentenceIdx]
 | 
					                const sentence = firstSentence[sentenceIdx]
 | 
				
			||||||
                if (!sentence) break
 | 
					                if (!sentence) break
 | 
				
			||||||
                finalDesc.push(sentence)
 | 
					                finalDesc.push(sentence)
 | 
				
			||||||
 | 
					                currentDescriptionLength += sentence.length
 | 
				
			||||||
                sentenceIdx++
 | 
					                sentenceIdx++
 | 
				
			||||||
              }
 | 
					              }
 | 
				
			||||||
              finalDesc.push("...")
 | 
					              finalDesc.push("...")
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
              while (finalDesc.length < len) {
 | 
					              while (currentDescriptionLength < len) {
 | 
				
			||||||
                const sentence = sentences[sentenceIdx]
 | 
					                const sentence = sentences[sentenceIdx]
 | 
				
			||||||
                if (!sentence) break
 | 
					                if (!sentence) break
 | 
				
			||||||
                finalDesc.push(sentence.endsWith(".") ? sentence : sentence + ".")
 | 
					                const currentSentence = sentence.endsWith(".") ? sentence : sentence + "."
 | 
				
			||||||
                sentenceIdx++
 | 
					                finalDesc.push(currentSentence)
 | 
				
			||||||
 | 
					                currentDescriptionLength += currentSentence.length
 | 
				
			||||||
              }
 | 
					              }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user