Initial commit

This commit is contained in:
Augusto Gunsch 2022-01-14 20:07:31 -03:00
commit 04e73e4d10
No known key found for this signature in database
GPG Key ID: F7EEFE29825C72DC
7 changed files with 104 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
venv/
files/
out/

1
README.md Normal file
View File

@ -0,0 +1 @@
Simple file manager

45
generate.py Executable file
View File

@ -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)

40
markdown.txt Normal file
View File

@ -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 <em>HTML</em> is possible

1
requirements.txt Normal file
View File

@ -0,0 +1 @@
markdown2

11
templates/base.html Normal file
View File

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<link rel="stylesheet" href="stylesheet.css"/>
<title>${title}</title>
</head>
<body>
${content}
</body>
</html>

3
templates/stylesheet.css Normal file
View File

@ -0,0 +1,3 @@
body {
background-color: blue
}