@@ -4,6 +4,7 @@ import fetch from 'node-fetch';
4
4
5
5
/**
6
6
* Stylizes a markdown body into an appropriate embed message style.
7
+ * Remove Carriage Return character to reduce size
7
8
* Remove HTML comments (commonly added by 'Generate release notes' button)
8
9
* Better URL linking for common Github links: PRs, Issues, Compare
9
10
* Redundant whitespace and newlines removed, keeping at max 2 to provide space between paragraphs
@@ -15,6 +16,7 @@ import fetch from 'node-fetch';
15
16
*/
16
17
const formatDescription = ( description ) => {
17
18
let edit = description
19
+ . replace ( / \r / g, '' )
18
20
. replace ( / < ! - - .* ?- - > / gs, '' )
19
21
. replace (
20
22
new RegExp (
@@ -94,21 +96,23 @@ function getContext () {
94
96
*
95
97
* @param {string } str
96
98
* @param {number } maxLength
97
- * @param {string= } url
99
+ * @param {string } [url]
100
+ * @param {boolean } [clipAtLine=false]
98
101
*/
99
- function limit ( str , maxLength , url ) {
102
+ function limit ( str , maxLength , url , clipAtLine ) {
103
+ clipAtLine ??= false
100
104
if ( str . length <= maxLength )
101
105
return str
102
- let replacement = '…'
106
+ let replacement = clipAtLine ? '\n…' : '…'
103
107
if ( url ) {
104
- replacement = `([ ${ replacement } ](${ url } ))`
108
+ replacement = `${ clipAtLine ? '\n' : '' } ([… ](${ url } ))`
105
109
}
106
110
maxLength = maxLength - replacement . length
107
111
str = str . substring ( 0 , maxLength )
108
112
109
- const lastWhitespace = str . search ( / [ ^ \s ] * $ / )
110
- if ( lastWhitespace > - 1 ) {
111
- str = str . substring ( 0 , lastWhitespace )
113
+ const lastNewline = str . search ( new RegExp ( `[^ ${ clipAtLine ? '\n' : '\s' } ]*$` ) )
114
+ if ( lastNewline > - 1 ) {
115
+ str = str . substring ( 0 , lastNewline )
112
116
}
113
117
114
118
return str + replacement
@@ -147,7 +151,7 @@ async function run () {
147
151
if ( footerTimestamp == 'true' ) embedMsg . timestamp = new Date ( ) . toISOString ( ) ;
148
152
149
153
let embedSize = embedMsg . title . length + ( embedMsg . footer ?. text ?. length ?? 0 )
150
- embedMsg . description = limit ( embedMsg . description , Math . min ( getMaxDescription ( ) , 6000 - embedSize ) , embedMsg . url )
154
+ embedMsg . description = limit ( embedMsg . description , Math . min ( getMaxDescription ( ) , 6000 - embedSize ) , embedMsg . url , true )
151
155
152
156
let requestBody = {
153
157
embeds : [ embedMsg ]
0 commit comments