Skip to content

Commit

Permalink
build: update changelog creation script to impose a 500 character lim…
Browse files Browse the repository at this point in the history
…it (#23)
  • Loading branch information
kieranroneill authored Nov 19, 2024
1 parent 66af784 commit 3567d5f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
23 changes: 21 additions & 2 deletions scripts/convert-markdown-to-plain-text.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
* Converts markdown to plain text, but retains ordered and unordered lists.
*
* @param {string} markdown - The markdown.
* @param {number} maxCharacterLimit - Maximum character limit.
* @returns {string | null} The markdown converted to plaintext, or null if no markdown is specified.
*/
function convertMarkdownToPlainText(markdown) {
function convertMarkdownToPlainText(markdown, maxCharacterLimit = 500) {
let charCount = 0;
let lines;
let plainText;
let truncatedText = '';

if (!markdown) {
console.log('no makrdown specified');
Expand All @@ -23,8 +27,23 @@ function convertMarkdownToPlainText(markdown) {
// remove inline code (`code`) and code blocks (```) -> code
plainText = plainText.replace(/`([^`]+)`/g, '$1');
plainText = plainText.replace(/```[\s\S]*?```/g, '');
// remove multiple blank lines
plainText = plainText.replace(/\n\s*\n+/g, '\n\n');

return plainText;
// split the text
lines = plainText.split('\n');

// truncate
for (const line of lines) {
if (charCount + line.length > maxCharacterLimit) {
break;
}

truncatedText += (truncatedText ? '\n' : '') + line;
charCount += line.length + 1;
}

return truncatedText;
}

export default convertMarkdownToPlainText;
5 changes: 4 additions & 1 deletion scripts/create-store-release-notes.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ function main(version, notes) {
process.exit(1);
}

releaseNotes = convertMarkdownToPlainText(notes);
releaseNotes = convertMarkdownToPlainText(
notes,
500 // google imposes a 500 character limit on changelogs
);

if (!releaseNotes) {
console.error('failed to convert the release notes to plain text');
Expand Down

0 comments on commit 3567d5f

Please sign in to comment.