this repo has no description

Add only titles that'll fit in bio

Changed files
+54 -20
+54 -20
script.ts
··· 44 44 45 45 if (response.ok) { 46 46 const json: any = await response.json(); 47 - 48 47 const currentlyReading = json?.data?.me?.[0]?.user_books; 49 - 50 - console.log(currentlyReading) 51 48 52 49 if (currentlyReading.length) { 53 50 return currentlyReading; ··· 70 67 }); 71 68 72 69 if (profile) { 73 - let bio = profile.data.description; 70 + let bio: string = profile.data.description; 74 71 75 72 if (bio) { 76 73 const currentlyReading = await getCurrentReads(); 77 - const formattedCurrentlyReading = currentlyReading 78 - .map( 79 - (cr: { 80 - book: { 81 - title: string; 82 - contributions: { author: { name: string } }[]; 83 - }; 84 - }) => 85 - `${cr.book.title} by ${cr.book.contributions[0].author.name}` 86 - ) 74 + const formattedCurrentlyReading = currentlyReading.map( 75 + (cr: { 76 + book: { 77 + title: string; 78 + contributions: { author: { name: string } }[]; 79 + }; 80 + }) => 81 + `${cr.book.title} by ${cr.book.contributions[0].author.name}` 82 + ); 87 83 88 - const regex = /(Currently Reading\n๐Ÿ“š)([\s\S]*?)(\n๐Ÿ“š)/; 84 + const regex = /(\nCurrently Reading\n๐Ÿ“š)([\s\S]*?)(\n๐Ÿ“š\n)/; 89 85 90 86 let newBio = ""; 91 87 92 88 if (regex.test(bio)) { 89 + const [full, prefix, middle, suffix] = bio.match(regex)!; 90 + 91 + let newMiddle: string[] = []; 92 + 93 + for (const cr of formattedCurrentlyReading) { 94 + if ( 95 + bio.replace( 96 + regex, 97 + [ 98 + prefix, 99 + newMiddle.join(""), 100 + `\n${cr}`, 101 + suffix 102 + ].join("") 103 + ).length <= 256 104 + ) { 105 + newMiddle.push(`\n${cr}`); 106 + } 107 + } 108 + 93 109 newBio = bio.replace( 94 110 regex, 95 - `$1\n${formattedCurrentlyReading}$3` 111 + [prefix, newMiddle.join(""), suffix].join("") 96 112 ); 97 113 } else { 98 - newBio = 99 - bio + 100 - "\n\n" + 101 - `Currently Reading\n๐Ÿ“š\n${formattedCurrentlyReading}\n๐Ÿ“š`; 114 + let newMiddle: string[] = []; 115 + 116 + for (const cr of formattedCurrentlyReading) { 117 + if ( 118 + [ 119 + bio, 120 + `\nCurrently Reading\n๐Ÿ“š`, 121 + newMiddle.join(""), 122 + `\n${cr}`, 123 + `\n๐Ÿ“š` 124 + ].join("").length <= 256 125 + ) { 126 + newMiddle.push(`\n${cr}`); 127 + } 128 + } 129 + 130 + newBio = [ 131 + bio, 132 + `\nCurrently Reading\n๐Ÿ“š`, 133 + newMiddle.join(""), 134 + `\n๐Ÿ“š` 135 + ].join(""); 102 136 } 103 137 104 138 if (newBio.length <= 256 && newBio !== bio) {