Skip to content

Commit

Permalink
Added formatting. Last before 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
qrno committed Dec 13, 2023
1 parent 9a1d499 commit 6f4c8fb
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
from markdown_it import MarkdownIt
from mdit_py_plugins.front_matter import front_matter_plugin
from jinja2 import Environment, FileSystemLoader
__version__ = "1.0.0"

import json
from pathlib import Path
import logging
import argparse
from markdown_it import MarkdownIt
from mdit_py_plugins.front_matter import front_matter_plugin
from jinja2 import Environment, FileSystemLoader

def render_page(text):
md = MarkdownIt('commonmark').use(front_matter_plugin)
md = MarkdownIt("commonmark").use(front_matter_plugin)

context = {'template' : 'default.html'}
context = {"template": "default.html"}
tokens = md.parse(text)
if tokens and tokens[0].type == 'front_matter':
if tokens and tokens[0].type == "front_matter":
front_matter = json.loads(tokens[0].content)
context.update(front_matter)
context['body'] = md.render(text)
context.update(front_matter)
context["body"] = md.render(text)

env = Environment(loader=FileSystemLoader('templates'))
template = env.get_template(context['template'])
env = Environment(loader=FileSystemLoader("templates"))
template = env.get_template(context["template"])
rendered = template.render(context)

return rendered
Expand All @@ -28,32 +30,31 @@ def generate_site(input_dir, output_dir):

output_path.mkdir(parents=True, exist_ok=True)

for md_file in input_path.rglob('*md'):
for md_file in input_path.rglob("*md"):
relative = md_file.relative_to(input_path)
html_path = output_path / relative.with_suffix('.html')
html_path = output_path / relative.with_suffix(".html")
html_path.parent.mkdir(parents=True, exist_ok=True)

with md_file.open() as f:
md_content = f.read()

html_content = render_page(md_content)
with html_path.open('w') as f:
with html_path.open("w") as f:
f.write(html_content)

logging.info(f'Processed: {md_file} -> {html_path}')

logging.info(f"Processed: {md_file} -> {html_path}")

if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Generate a website from markdown files.')
parser.add_argument('--input', '-i', default='content', help='Input directory with the markdown files.')
parser.add_argument('--output', '-o', default='output', help='Output directory to store generated HTML files.')
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Generate a website from markdown files.")
parser.add_argument("--input", "-i", default="content", help="Input directory with the markdown files.")
parser.add_argument("--output", "-o", default="output", help="Output directory to store generated HTML files.",)
args = parser.parse_args()

logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")

input_dir = 'content'
output_dir = 'output'
input_dir = args.input
output_dir = args.output

logging.info(f'Starting build. Input directory: {input_dir}, Output directory {output_dir}')
logging.info(f"Starting build. Input directory: {input_dir}, Output directory {output_dir}")
generate_site(input_dir, output_dir)
logging.info('Mirror build completed.')
logging.info("Build complete")

0 comments on commit 6f4c8fb

Please sign in to comment.