Skip to content

Commit

Permalink
Merge pull request #1513 from MunGell/templating-workflow
Browse files Browse the repository at this point in the history
Replace current README GitHub workflow script with a templating one
  • Loading branch information
sammyhori authored Nov 17, 2024
2 parents ecb73e0 + 2deeb0e commit c018a9d
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 96 deletions.
14 changes: 9 additions & 5 deletions .github/tpl.md → .github/README.j2
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,25 @@ If you are a maintainer of open-source projects, add the label `first-timers-onl
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 %>
{% 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 %})_ <br> {{ entry.description }}{% endfor %}
{% endfor %}

## Contribute

Contributions are welcome! See the [contributing guidelines](CONTRIBUTING.md).

## Thanks to GitHub Sponsors

<% sponsors %>
<table><tr>{% for sponsor in sponsors %}{% if loop.index != 1 and (loop.index - 1) % 6 == 0 %}</tr><tr>{% endif %}<td align="center"><a href="{{ sponsor.link }}"><img src="{{ sponsor.image }}" width="60px;" alt=""/><br/><sub><b>{{ sponsor.name }}</b></sub></a></td>{% endfor %}</tr></table>

## 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.

87 changes: 0 additions & 87 deletions .github/scripts/build.js

This file was deleted.

40 changes: 40 additions & 0 deletions .github/scripts/render-readme.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from jinja2 import Environment, FileSystemLoader
import json

DATAFILE = "./data.json"
TEMPLATEPATH = "./.github/"
TEMPLATEFILE = "README.j2"
TARGETFILE = "./README.md"

technologies = {}

with open(DATAFILE, '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(TEMPLATEPATH))

template = env.get_template(TEMPLATEFILE)

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(TARGETFILE, "w").write(output)
7 changes: 3 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit c018a9d

Please sign in to comment.