commit 04e73e4d10225a470e94258ee79cec3b30b10703 Author: Augusto Gunsch Date: Fri Jan 14 20:07:31 2022 -0300 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..07c713b --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +venv/ +files/ +out/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..1536675 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +Simple file manager diff --git a/generate.py b/generate.py new file mode 100755 index 0000000..85a1a6c --- /dev/null +++ b/generate.py @@ -0,0 +1,45 @@ +#!python +import os +import shutil +from markdown2 import markdown + +input_ = 'files' +output = 'out' +templates = 'templates' + + +def render_template(**kwargs): + expanded = template[:] + + for var, val in kwargs.items(): + expanded = expanded.replace('${%s}' % var, val) + + return expanded + + +with open(templates + '/base.html', 'r') as template: + template = template.read() + +for root, dirs, files in os.walk(input_, topdown=True): + outroot = output + root[len(input_):] + + os.makedirs(outroot, exist_ok=True) + + shutil.copy(templates + '/stylesheet.css', outroot + '/stylesheet.css') + + for file in files: + if file.endswith('.md'): + basename = file[:-3] + outfile = outroot + '/' + basename + '.html' + infile = root + '/' + file + + with open(infile, 'r') as f: + content = f.read() + + with open(outfile, 'w') as f: + content = markdown(content) + + new_file = render_template(title=basename, + content=content) + + f.write(new_file) diff --git a/markdown.txt b/markdown.txt new file mode 100644 index 0000000..912a6a1 --- /dev/null +++ b/markdown.txt @@ -0,0 +1,40 @@ +# Header 1 +## Header 2 +### Header 3 +#### Header 4 +##### Header 5 +###### Header 6 + +This is a paragraph. + +This is another one. They are separated by 2 new lines. +So this one is the same paragraph. +And to have a line break, leave 2 trailing whitespaces, like +in the previous line. + +And there is **bold text**. And *italic* + +> Blockquoted. +> +> With multiple paragraphs. +>> And a nested quote. + +1. Ordered list +2. Very orderly +3. And nice + +- Unordered list +- Messy +- But nice too + +`inline code here` + +``` +Block code +``` + +![Image alt description](/url/to/image) + +[Links are similar](https://linksomewhere.com) + +Inline HTML is possible diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..b5d9211 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +markdown2 diff --git a/templates/base.html b/templates/base.html new file mode 100644 index 0000000..1589ae6 --- /dev/null +++ b/templates/base.html @@ -0,0 +1,11 @@ + + + + + + ${title} + + + ${content} + + diff --git a/templates/stylesheet.css b/templates/stylesheet.css new file mode 100644 index 0000000..762eab3 --- /dev/null +++ b/templates/stylesheet.css @@ -0,0 +1,3 @@ +body { + background-color: blue +}