Commit 5ce0cb7a authored by Christophe Benz's avatar Christophe Benz

Sort schemas by title in generated summary

parent 0e619399
Pipeline #1181 passed with stages
in 1 minute and 20 seconds
#!/usr/bin/env python3
"""
Generate assets from a catalog of schemas.
"""
import argparse
import itertools
import logging
import subprocess
import sys
import unicodedata
from pathlib import Path
from urllib.parse import urljoin
import requests
from jinja2 import Template
from opendataschema import GitSchemaReference, SchemaCatalog, by_commit_date
log = logging.getLogger(__name__)
......@@ -94,16 +96,21 @@ def main():
log.info("Generating SUMMARY.md for GitBook...")
summary_template = Template(args.summary_j2.read_text())
summary_md = summary_template.render(schemas=[
summary_md = summary_template.render(schemas=sorted([
{
"name": name,
"title": schema_json_by_name.get(name, {}).get("title", name)
"title": schema_json.get("title", name)
}
for name in sorted(schema_json_by_name.keys())
])
for name, schema_json in schema_json_by_name.items()
], key=lambda v: strip_accents(v['title'].lower())))
with args.summary_md.open("w") as fd:
fd.write(summary_md)
def strip_accents(s):
"""Remove accents from string, used to sort normalized strings"""
return ''.join(c for c in unicodedata.normalize('NFD', s) if unicodedata.category(c) != 'Mn')
if __name__ == '__main__':
sys.exit(main())
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment