You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2.8 KiB
2.8 KiB
In [1]:
import os import frontmatter from datetime import datetime from mako.template import Template
In [2]:
def list_folders(folder): ''' Return all the folders in a folder ''' names = [] for entry in os.scandir(folder): # add to the list only proper files if not entry.name.startswith('.') and entry.is_dir(): # remove the extension from the filename names.append(entry.name) return names / def get_md_contents(filename, directory='./contents'): ''' Return contents from a filename as frontmatter handler ''' with open(f"{directory}/{filename}", "r") as f: metadata, content = frontmatter.parse(f.read()) return metadata, content
In [18]:
import mako.runtime mako.runtime.UNDEFINED = '' folders = list_folders('../') projects = [] for folder in folders: project, content = get_md_contents('documentation.md', f'../{folder}') project_date = datetime.strptime(project['date'], '%d/%m/%Y') project['date'] = datetime.strftime(project_date, '%d %b, %y') project['slug'] = folder project['categories'].sort() projects.append(project) projects.sort(reverse=False, key=lambda project: datetime.strptime( project['date'], '%d %b, %y')) baloons = Template(filename="baloons_web.html") with open('output.html', 'w') as f: f.write(baloons.render(projects=projects))
In [ ]: