-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1513 from MunGell/templating-workflow
Replace current README GitHub workflow script with a templating one
- Loading branch information
Showing
4 changed files
with
52 additions
and
96 deletions.
There are no files selected for viewing
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
This file was deleted.
Oops, something went wrong.
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
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) |
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