Created
December 10, 2021 20:52
-
-
Save terremoth/423c6a48d0fef89133b3646623d4280d to your computer and use it in GitHub Desktop.
Add license badges to all projects in felipefialho/awesome-made-by-brazilians repo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$aFile = file('README.md', FILE_TEXT); | |
$licensed_file = fopen('NEW_README.md', 'wb+'); | |
// Stub: [](/LICENSE) | |
// pattern to search =  | |
foreach ($aFile as $line_num => $line) { | |
$matches = null; | |
if (preg_match('/\!\[Stars\].*\)/', $line, $matches)) { | |
$stars_line = $matches[0]; | |
$star_url_parts = explode('/', $stars_line); | |
$author = $star_url_parts[5]; | |
$repo_name_dirty = $star_url_parts[6]; | |
$repo_name_clean = explode("?", $repo_name_dirty)[0]; // remove ?style=flat-square from the new URL | |
$repo_name_clean = implode('', explode(".svg", $repo_name_clean)); // remove .svg from repo name | |
$license_url = "[](/LICENSE)"; | |
echo $license_url.PHP_EOL; | |
fwrite($licensed_file, $line.' '.$license_url.PHP_EOL); | |
} else { | |
fwrite($licensed_file, $line); | |
} | |
} | |
fclose($licensed_file); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment