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.

109 lines
2.8 KiB
Plaintext

3 years ago
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "6f73330a-e0d5-4d22-a4c7-246b928394e9",
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import frontmatter\n",
"from datetime import datetime\n",
"\n",
"from mako.template import Template\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "3d183b25-72fb-4b90-a639-188a68e02fc1",
"metadata": {},
"outputs": [],
"source": [
"def list_folders(folder):\n",
" ''' Return all the folders in a folder '''\n",
" names = []\n",
" for entry in os.scandir(folder):\n",
" # add to the list only proper files\n",
" if not entry.name.startswith('.') and entry.is_dir():\n",
" # remove the extension from the filename\n",
" names.append(entry.name)\n",
" return names\n",
"/\n",
"def get_md_contents(filename, directory='./contents'):\n",
" ''' Return contents from a filename as frontmatter handler '''\n",
" with open(f\"{directory}/{filename}\", \"r\") as f:\n",
" metadata, content = frontmatter.parse(f.read())\n",
" return metadata, content\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
3 years ago
"execution_count": 4,
3 years ago
"id": "a7b4d409-d42d-4a74-b093-10ace148cc71",
"metadata": {},
"outputs": [],
"source": [
"import mako.runtime\n",
"mako.runtime.UNDEFINED = ''\n",
"\n",
"\n",
"\n",
"folders = list_folders('../')\n",
"projects = []\n",
"\n",
"for folder in folders:\n",
" project, content = get_md_contents('documentation.md', f'../{folder}')\n",
" project_date = datetime.strptime(project['date'], '%d/%m/%Y')\n",
" project['date'] = datetime.strftime(project_date, '%d %b, %y')\n",
" project['slug'] = folder\n",
" project['categories'].sort()\n",
" projects.append(project)\n",
"\n",
"projects.sort(reverse=False, key=lambda project: datetime.strptime(\n",
" project['date'], '%d %b, %y'))\n",
"\n",
3 years ago
"baloons = Template(filename=\"baloons.html\")\n",
3 years ago
"\n",
"with open('output.html', 'w') as f:\n",
" f.write(baloons.render(projects=projects))\n",
"\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "faa6e297-3685-415a-8617-f3f4198da21d",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}