Skip to content

Generate a categorised README using a yaml definition #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dotenv_if_exists
use flake
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.direnv
3 changes: 3 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Task to generate README from list.yml
generate-readme:
python3 generate_readme.py list.yml README.md
2,393 changes: 1,381 additions & 1,012 deletions README.md

Large diffs are not rendered by default.

59 changes: 59 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
inputs = {
flake-utils.url = "github:numtide/flake-utils";
};

outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
pythonEnv = pkgs.python3.withPackages (ps: with ps; [
pyyaml
]);
in
{
devShell = pkgs.mkShell {
buildInputs = with pkgs; [
pythonEnv
just
];
};
});
}
41 changes: 41 additions & 0 deletions generate_readme.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import yaml
import sys
from collections import defaultdict

def generate_readme(input_file, output_file):
with open(input_file, 'r') as f:
data = yaml.safe_load(f)

categories = defaultdict(list)
duplicates = []

# Each item in the list is a dictionary with:
# - category: The category of the repository
# - repo_url: The URL of the repository
# - description: A short description of the repository

for item in data:
category = item.get('category', 'Uncategorized')
categories[category].append(item)

# Sort categories and items
sorted_categories = sorted(categories.items())

with open(output_file, 'w') as f:
for category, repos in sorted_categories:
f.write(f"## {category}\n\n")
for repo in sorted(repos, key=lambda x: x['repo_url']):
repo_path = repo['repo_url'].split('/')
repo_name = repo_path[-1]
if repo_name in duplicates:
repo_name = repo_path[-2] + '/' + repo_path[-1]
f.write(f"* [{repo_name}]({repo['repo_url']}) - {repo['description']}\n")
f.write("\n")

if __name__ == "__main__":
if len(sys.argv) != 3:
print("Usage: python3 generate_readme.py <input_file> <output_file>")
sys.exit(1)

generate_readme(sys.argv[1], sys.argv[2])

Loading