From f581020ab621845f4b4609bfbca6fccdfea0cb49 Mon Sep 17 00:00:00 2001 From: Sammy Hori Date: Sun, 17 Nov 2024 20:58:03 +0000 Subject: [PATCH 1/5] WIP: Added new script for building the README This uses jinja templating to do so. The script is made to exactly copy the behaviour of the current script as now, to prove that it does the same thing. --- .github/README.j2 | 31 ++++++++++++++++++++++++++++ .github/scripts/render-readme.py | 35 ++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 .github/README.j2 create mode 100644 .github/scripts/render-readme.py diff --git a/.github/README.j2 b/.github/README.j2 new file mode 100644 index 0000000..c9cf47e --- /dev/null +++ b/.github/README.j2 @@ -0,0 +1,31 @@ +# Awesome First PR Opportunities [![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/sindresorhus/awesome) + +Inspired by [First Timers Only](https://kentcdodds.com/blog/first-timers-only) blog post. + +If you are a maintainer of open-source projects, add the label `first-timers-only` (or similar) to your project and list it here so that people can find it. + +If you are not a programmer but would like to contribute, check out the [Awesome for non-programmers](https://github.com/szabgab/awesome-for-non-programmers) list. + +## Table of Contents: +{% for category in categories %} +- [{{ category.title }}](#{{ category.link_id }}){% endfor %} +{% for category in categories %} +## {{ category.title }} +{% for entry in category.entries %} +- [{{ entry.name }}]({{ entry.link }}) _(label: {% if entry.label is defined %}{{ entry.label }}{% else %}n/a{% endif %})_
{{ entry.description }}{% endfor %} +{% endfor %} + +## Contribute + +Contributions are welcome! See the [contributing guidelines](CONTRIBUTING.md). + +## Thanks to GitHub Sponsors + +{% for sponsor in sponsors %}{% endfor %}

{{ sponsor.name }}
+ +## License + +[![CC0](http://i.creativecommons.org/p/zero/1.0/88x31.png)](http://creativecommons.org/publicdomain/zero/1.0/) + +To the extent possible under law, the author has waived all copyrights and related or neighboring rights to this work. + diff --git a/.github/scripts/render-readme.py b/.github/scripts/render-readme.py new file mode 100644 index 0000000..02d4e64 --- /dev/null +++ b/.github/scripts/render-readme.py @@ -0,0 +1,35 @@ +from jinja2 import Environment, FileSystemLoader +import json + +technologies = {} + +with open("../../data.json", 'r') as datafile: + data = json.loads(datafile.read()) + +for technology in data["technologies"]: + technologies[technology] = {"link_id": data["technologies"][technology], "entries": []} + +for repository in data["repositories"]: + repo_technologies = repository["technologies"] + for repo_technology in repo_technologies: + if not technologies.get(repo_technology, False): + technologies[repo_technology] = {"link_id": repo_technology.lower(), "entries": []} + technologies[repo_technology]["entries"].append(repository) + +env = Environment(loader = FileSystemLoader("..")) + +template = env.get_template("README.j2") + +categories = [] +for key, value in zip(technologies.keys(), technologies.values()): + categories.append({"title": key, "link_id": value["link_id"], "entries": value["entries"]}) + +categories = sorted(categories, key=lambda x: x["title"].upper()) +for category in categories: + category["entries"] = sorted(category["entries"], key=lambda x: x["name"].upper()) + +sponsors = data["sponsors"] + +output = template.render(categories=categories, sponsors=sponsors) + +open("README.md", "w").write(output) From fe164b7153e7cff3e1c6125a2f9c935c53c09367 Mon Sep 17 00:00:00 2001 From: Sammy Hori Date: Sun, 17 Nov 2024 20:58:37 +0000 Subject: [PATCH 2/5] Made changes to the filepaths to enable running of the script from the repo root. --- .github/scripts/render-readme.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) mode change 100644 => 100755 .github/scripts/render-readme.py diff --git a/.github/scripts/render-readme.py b/.github/scripts/render-readme.py old mode 100644 new mode 100755 index 02d4e64..8f3673d --- a/.github/scripts/render-readme.py +++ b/.github/scripts/render-readme.py @@ -1,9 +1,14 @@ from jinja2 import Environment, FileSystemLoader import json +DATAFILE = "./data.json" +TEMPLATEPATH = "./.github/" +TEMPLATEFILE = "README.j2" +TARGETFILE = "./README.md" + technologies = {} -with open("../../data.json", 'r') as datafile: +with open(DATAFILE, 'r') as datafile: data = json.loads(datafile.read()) for technology in data["technologies"]: @@ -16,9 +21,9 @@ for repository in data["repositories"]: technologies[repo_technology] = {"link_id": repo_technology.lower(), "entries": []} technologies[repo_technology]["entries"].append(repository) -env = Environment(loader = FileSystemLoader("..")) +env = Environment(loader = FileSystemLoader(TEMPLATEPATH)) -template = env.get_template("README.j2") +template = env.get_template(TEMPLATEFILE) categories = [] for key, value in zip(technologies.keys(), technologies.values()): @@ -32,4 +37,4 @@ sponsors = data["sponsors"] output = template.render(categories=categories, sponsors=sponsors) -open("README.md", "w").write(output) +open(TARGETFILE, "w").write(output) From b531c33c6b43f869426df002baac64c3b6ec9e19 Mon Sep 17 00:00:00 2001 From: Sammy Hori Date: Sun, 17 Nov 2024 21:45:43 +0000 Subject: [PATCH 3/5] Changed github workflow to run new script --- .github/workflows/build.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9ede61e..aaafdcc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,11 +13,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - uses: actions/setup-node@v2 - with: - node-version: "16.x" + - name: install jinja2 + run: sudo pip install jinja2 - name: Build - run: node .github/scripts/build.js + run: python3 .github/scripts/render-readme.py - name: Commit run: | git config --global user.name 'Shmavon Gazanchyan' From 445e53bc48bd85a6b08eb98e30fbd82ce980afac Mon Sep 17 00:00:00 2001 From: Sammy Hori Date: Sun, 17 Nov 2024 21:48:11 +0000 Subject: [PATCH 4/5] Removed old script and template --- .github/scripts/build.js | 87 ---------------------------------------- .github/tpl.md | 27 ------------- 2 files changed, 114 deletions(-) delete mode 100644 .github/scripts/build.js delete mode 100644 .github/tpl.md diff --git a/.github/scripts/build.js b/.github/scripts/build.js deleted file mode 100644 index cb9d433..0000000 --- a/.github/scripts/build.js +++ /dev/null @@ -1,87 +0,0 @@ -const fs = require('fs'); -const data = require('../../data.json'); - -const TPL_FILE = './.github/tpl.md'; -const TARGET = './README.md'; - -const tpl = getTemplate(TPL_FILE); - -const categories = {}; - -data.repositories.sort((a, b) => { - const nameA = a.name.toUpperCase(); - const nameB = b.name.toUpperCase(); - if (nameA < nameB) { - return -1; - } - if (nameA > nameB) { - return 1; - } - return 0; -}).forEach(repo => - repo.technologies.forEach(tech => { - if (!categories.hasOwnProperty(tech)) { - categories[tech] = []; - } - categories[tech].push(repo); - })) - -const sortedCategories = Object.fromEntries(Object.entries(categories).sort((a, b) => { - const nameA = a[0].toUpperCase(); - const nameB = b[0].toUpperCase(); - if (nameA < nameB) { - return -1; - } - if (nameA > nameB) { - return 1; - } - return 0; -})); - -const toc = Object.keys(sortedCategories) - .map(t => `- [${t}](#${data.technologies[t] || t.toLowerCase()})`) - .join('\n'); - -const content = Object.keys(sortedCategories) - .map(category => { - const repos = sortedCategories[category].map(repo => `- [${repo.name}](${repo.link}) _(label: ${repo.label || 'n/a'})_
${repo.description}`).join('\n') - return `## ${category}\n\n${repos}\n` - }).join('\n'); - -const sponsorList = data.sponsors.map(sponsor => `
${sponsor.name}
`) -const sponsorRows = Math.ceil(sponsorList.length / 6); - -let sponsors = ''; - -for (let i = 1; i <= sponsorRows; i++) { - sponsors += ''; - for(let j = 0; j < 6; j++) { - if (sponsorList.length > i*j) { - sponsors += sponsorList[i*j]; - } else if (sponsorRows > 1) { - sponsors += '' - } - } - sponsors += ''; -} - -sponsors = `${sponsors}
` - -saveFile(TARGET, render(tpl, { toc, content, sponsors })); - -function getTemplate(file) { - return fs.readFileSync(file).toString(); -} - -function saveFile(file, contents) { - return fs.writeFileSync(file, contents); -} - -function render(template, variables) { - Object - .entries(variables) - .forEach(([key, value]) => { - template = template.replace(new RegExp(`<% ${key} %>`, 'g'), value); - }); - return template; -} diff --git a/.github/tpl.md b/.github/tpl.md deleted file mode 100644 index 85fe672..0000000 --- a/.github/tpl.md +++ /dev/null @@ -1,27 +0,0 @@ -# Awesome First PR Opportunities [![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/sindresorhus/awesome) - -Inspired by [First Timers Only](https://kentcdodds.com/blog/first-timers-only) blog post. - -If you are a maintainer of open-source projects, add the label `first-timers-only` (or similar) to your project and list it here so that people can find it. - -If you are not a programmer but would like to contribute, check out the [Awesome for non-programmers](https://github.com/szabgab/awesome-for-non-programmers) list. - -## Table of Contents: - -<% toc %> - -<% content %> - -## Contribute - -Contributions are welcome! See the [contributing guidelines](CONTRIBUTING.md). - -## Thanks to GitHub Sponsors - -<% sponsors %> - -## License - -[![CC0](http://i.creativecommons.org/p/zero/1.0/88x31.png)](http://creativecommons.org/publicdomain/zero/1.0/) - -To the extent possible under law, the author has waived all copyrights and related or neighboring rights to this work. From 2deeb0e5e303d6e6a5ce093af0dbb2b7b77a1653 Mon Sep 17 00:00:00 2001 From: Sammy Hori Date: Sun, 17 Nov 2024 22:10:11 +0000 Subject: [PATCH 5/5] Set the sponsors table new row every 6 entries. This copies the behaviour of the old script. --- .github/README.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/README.j2 b/.github/README.j2 index c9cf47e..67942e2 100644 --- a/.github/README.j2 +++ b/.github/README.j2 @@ -21,7 +21,7 @@ Contributions are welcome! See the [contributing guidelines](CONTRIBUTING.md). ## Thanks to GitHub Sponsors -{% for sponsor in sponsors %}{% endfor %}

{{ sponsor.name }}
+{% for sponsor in sponsors %}{% if loop.index != 1 and (loop.index - 1) % 6 == 0 %}{% endif %}{% endfor %}

{{ sponsor.name }}
## License