Skip to content

Commit

Permalink
fix(description): counts characters instead of words (jackyzha0#972)
Browse files Browse the repository at this point in the history
* fix(description): make sure description counts characters instead of words

* ref: removed duplicate ternary
  • Loading branch information
saberzero1 authored Mar 8, 2024
1 parent 141dd3b commit 6d59aa8
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions quartz/plugins/transformers/description.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,25 @@ export const Description: QuartzTransformerPlugin<Partial<Options> | 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
}
}

Expand Down

0 comments on commit 6d59aa8

Please sign in to comment.