Skip to content

Add helper function for truncating strings with an ellipsis#968

Merged
carrythebanner merged 2 commits intoshift-org:mainfrom
carrythebanner:truncate-descr
Mar 20, 2026
Merged

Add helper function for truncating strings with an ellipsis#968
carrythebanner merged 2 commits intoshift-org:mainfrom
carrythebanner:truncate-descr

Conversation

@carrythebanner
Copy link
Collaborator

Use for OpenGraph tag and export to Google Calendar.

@carrythebanner carrythebanner marked this pull request as ready for review March 20, 2026 01:46
@carrythebanner carrythebanner merged commit 2dc9166 into shift-org:main Mar 20, 2026
4 checks passed
@carrythebanner carrythebanner deleted the truncate-descr branch March 20, 2026 01:53
text = text.slice(0, -1) + "…";
}
return text;
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could do something like this if you wanted to avoid that first substr call that goes unused if the length is small enough

{
        if (str.length < maxLength) {
            return str; 
        } else {
          // replace the last character with an ellipsis
           let text = str.substring(0,maxLength-1) + "…";
           return text;
        }
    };

Copy link
Contributor

@ionous ionous left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants