1
0
mirror of https://github.com/ryanoasis/nerd-fonts.git synced 2024-11-25 16:47:37 +02:00

Rewrite update-contributors

[why]
The script is not a 'proper' script with shebang.
The CONTRIBUTORS.md format changed.
We want to incorporate this as CI workflow.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
This commit is contained in:
Fini Jastrow 2023-01-27 15:10:38 +01:00
parent 7e3b7fb6be
commit 1ed2faccfa

View File

@ -1,54 +1,39 @@
#!/usr/bin/env python3
import fileinput import fileinput
import string import string
import re import re
print("* reading CONTRIBUTORS.md")
file = open("../../CONTRIBUTORS.md", "r") file = open("../../CONTRIBUTORS.md", "r")
contributorContents = file.read() contributorContents = file.read()
file.close() file.close()
# print(contributorContents) print("* reading post")
file = open("../../_posts/2017-01-05-all-contributors.md", "r")
file = open("/home/ryan/projects/nerd-fonts-gh-pages/_posts/2017-01-05-all-contributors.md", "r")
webContributorContents = file.read() webContributorContents = file.read()
file.close() file.close()
# print(webContributorContents) print("* find fences")
# search and replace
starting_text = '<!-- UPDATE START -->' starting_text = '<!-- UPDATE START -->'
ending_text = '<!-- UPDATE END -->' ending_text = '<!-- UPDATE END -->'
to_replace = webContributorContents[webContributorContents.find(starting_text)+len(starting_text):webContributorContents.rfind(ending_text)] wCC_start = webContributorContents.find(starting_text) + len(starting_text)
wCC_end = webContributorContents.rfind(ending_text)
print('re replace') starting_text = '<!-- ALL-CONTRIBUTORS-LIST:START '
print('-------------------------------------------------') ending_text = '<!-- ALL-CONTRIBUTORS-LIST:END -->'
print(to_replace) cC_start = contributorContents.find(starting_text)
cC_end = contributorContents.rfind(ending_text) + len(ending_text)
# Remove markdown that won't work as-is in the jekyll page: transformedContributorContents = contributorContents[cC_start:cC_end]
transformedContributorContents = re.sub('[![All Contributors](.*)\(#contributors\)\n', '', contributorContents)
transformedContributorContents = re.sub('Thanks goes to these wonderful people(.*):\n', '', transformedContributorContents)
transformedContributorContents = string.replace(transformedContributorContents, '## Contributors\n\n', '')
transformedContributorContents = string.replace(transformedContributorContents, 'This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!', '')
# Fix the formatting for the grid table: print('* improving table')
transformedContributorContents = string.replace(transformedContributorContents, ' [<img src=', '\n<div markdown="1">\n[<img class="lzy_img" data-src=') transformedContributorContents = transformedContributorContents.replace('<img src=', '<img class="lzy_img" data-src=')
transformedContributorContents = string.replace(transformedContributorContents, '") |', '")\n</div>')
transformedContributorContents = string.replace(transformedContributorContents, '| :---: | :---: | :---: | :---: | :---: | :---: | :---: |', '')
transformedContributorContents = string.replace(transformedContributorContents, '<!-- ALL-CONTRIBUTORS-LIST:END -->', '')
transformedContributorContents = string.replace(transformedContributorContents, '|\n', '') # @TODO fixme
print('* final out')
webContributorContents = (webContributorContents[:wCC_start]
+ "\n" + transformedContributorContents
+ "\n" + webContributorContents[wCC_end:])
print('transformed contr contents') file = open("../../_posts/2017-01-05-all-contributors.md", "w")
print('-------------------------------------------------')
print(transformedContributorContents)
webContributorContents = string.replace(webContributorContents, to_replace, transformedContributorContents)
print('final out')
print('-------------------------------------------------')
print(webContributorContents)
# write the updated all contributors to the website
file = open("/home/ryan/projects/nerd-fonts-gh-pages/_posts/2017-01-05-all-contributors.md", "w")
file.write(webContributorContents) file.write(webContributorContents)
file.close()