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.
68 lines
1.8 KiB
Python
68 lines
1.8 KiB
Python
1 year ago
|
import os
|
||
|
from jinja2 import Environment, Template
|
||
|
import markdown
|
||
|
|
||
|
# Configuration
|
||
|
materials = ['1_situation', '2_binding', '3_paperformat', '4_add_ons']
|
||
|
output_file = 'output.html'
|
||
|
|
||
|
# Prepare data for template rendering
|
||
|
data = []
|
||
|
for folder in materials:
|
||
|
markdown_files = os.listdir(folder)
|
||
|
folder_data = {
|
||
|
'folder_name': folder,
|
||
|
'markdown_files': []
|
||
|
}
|
||
|
for markdown_file in markdown_files:
|
||
|
file_path = os.path.join(folder, markdown_file)
|
||
|
with open(file_path, 'r') as file:
|
||
|
content = file.read()
|
||
|
folder_data['markdown_files'].append({'file_name': markdown_file, 'content': content})
|
||
|
data.append(folder_data)
|
||
|
|
||
|
# Define the HTML template
|
||
|
template = """
|
||
|
<!DOCTYPE html>
|
||
|
<html>
|
||
|
<head>
|
||
|
<title>Markdown Folders</title>
|
||
|
<style>
|
||
|
/* CSS styling goes here */
|
||
|
</style>
|
||
|
</head>
|
||
|
<body>
|
||
|
<div class="container">
|
||
|
{% for folder_data in data %}
|
||
|
<div class="column">
|
||
|
<div class="folder">
|
||
|
<h2>{{ folder_data.folder_name }}</h2>
|
||
|
<ul>
|
||
|
{% for file_data in folder_data.markdown_files %}
|
||
|
<li>
|
||
|
<h3>{{ file_data.file_name }}</h3>
|
||
|
<div>{{ file_data.content }}</div>
|
||
|
</li>
|
||
|
{% endfor %}
|
||
|
</ul>
|
||
|
</div>
|
||
|
</div>
|
||
|
{% endfor %}
|
||
|
</div>
|
||
|
</body>
|
||
|
</html>
|
||
|
"""
|
||
|
|
||
|
# Create the Jinja2 environment
|
||
|
env = Environment()
|
||
|
|
||
|
# Create the template from the template string
|
||
|
template = env.from_string(template)
|
||
|
|
||
|
# Render the template with data
|
||
|
html_output = template.render(data=data)
|
||
|
|
||
|
# Write the HTML output to file
|
||
|
with open(output_file, 'w') as file:
|
||
|
file.write(html_output)
|