reshuffled license (now CC0 in license text), moved tocs to subfolder and added tocs for platform

This commit is contained in:
Trilarion
2019-09-09 12:41:32 +02:00
parent 1581152bc3
commit d779cefbb0
56 changed files with 3191 additions and 2459 deletions

View File

@ -28,17 +28,15 @@ def update_readme_and_tocs(infos):
"""
print('update readme and toc files')
# delete all toc files
entries = os.listdir(games_path)
entries = (x for x in entries if x.startswith('_'))
for entry in entries:
os.remove(os.path.join(games_path, entry))
# delete content of toc path
for file in os.listdir(tocs_path):
os.remove(os.path.join(tocs_path, file))
# read readme
readme_file = os.path.join(root_path, 'README.md')
readme_text = read_text(readme_file)
# compile regex for identifying the building blocks
# compile regex for identifying the building blocks in the readme
regex = re.compile(r"(.*?)(\[comment\]: # \(start.*?end of autogenerated content\))(.*)", re.DOTALL)
# apply regex
@ -49,27 +47,37 @@ def update_readme_and_tocs(infos):
start = matches[0]
end = matches[2]
# create all toc and readme entry
# create all toc
title = 'All'
file = '_all.md'
update_prefix = '**[{}](games/{}#{})** ({})'.format(title, file, title, len(infos))
tocs_text = '**[{}](games/tocs/{}#{})** ({})\n'.format(title, file, title, len(infos))
create_toc(title, file, infos)
update = []
# create by category
categories_text = []
for keyword in recommended_keywords:
infos_filtered = [x for x in infos if keyword in x['keywords']]
title = keyword.capitalize()
name = keyword.replace(' ', '-')
file = '_{}.md'.format(name)
update.append('**[{}](games/{}#{})** ({})'.format(title, file, name, len(infos_filtered)))
categories_text.append('**[{}](games/tocs/{}#{})** ({})'.format(title, file, name, len(infos_filtered)))
create_toc(title, file, infos_filtered)
update.sort()
update.insert(0, update_prefix)
update = ', '.join(update)
update += '\n'
categories_text.sort()
tocs_text += '\nBy category: {}\n'.format(', '.join(categories_text))
# create by platform
platforms_text = []
for platform in valid_platforms:
infos_filtered = [x for x in infos if platform in x.get('platform', [])]
title = platform
name = platform.lower()
file = '_{}.md'.format(name)
platforms_text.append('**[{}](games/tocs/{}#{})** ({})'.format(title, file, name, len(infos_filtered)))
create_toc(title, file, infos_filtered)
tocs_text += '\nBy platform: {}\n'.format(', '.join(platforms_text))
# insert new text in the middle (the \n before the second comment is necessary, otherwise Markdown displays it as part of the bullet list)
text = start + "[comment]: # (start of autogenerated content, do not edit)\n" + update + "\n[comment]: # (end of autogenerated content)" + end
text = start + "[comment]: # (start of autogenerated content, do not edit)\n" + tocs_text + "\n[comment]: # (end of autogenerated content)" + end
# write to readme
write_text(readme_file, text)
@ -80,7 +88,7 @@ def create_toc(title, file, entries):
"""
# file path
toc_file = os.path.join(games_path, file)
toc_file = os.path.join(tocs_path, file)
# header line
text = '[comment]: # (autogenerated content, do not edit)\n# {}\n\n'.format(title)
@ -88,7 +96,7 @@ def create_toc(title, file, entries):
# assemble rows
rows = []
for entry in entries:
rows.append('- **[{}]({})** ({})'.format(entry['name'], entry['file'], ', '.join(entry['code language'] + entry['code license'] + entry['state'])))
rows.append('- **[{}]({})** ({})'.format(entry['name'], '../' + entry['file'], ', '.join(entry['code language'] + entry['code license'] + entry['state'])))
# sort rows (by title)
rows.sort(key=str.casefold)
@ -779,6 +787,7 @@ if __name__ == "__main__":
# paths
root_path = os.path.realpath(os.path.join(os.path.dirname(__file__), os.path.pardir))
games_path = os.path.join(root_path, 'games')
tocs_path = os.path.join(games_path, 'tocs')
# backlog
game_urls = extract_links(games_path)