mirror of
https://github.com/venthur/blag.git
synced 2025-11-25 20:52:43 +00:00
WIP
This commit is contained in:
31
sg/sg.py
31
sg/sg.py
@@ -72,22 +72,21 @@ def build(args):
|
|||||||
convertibles = []
|
convertibles = []
|
||||||
for root, dirnames, filenames in os.walk(args.input_dir):
|
for root, dirnames, filenames in os.walk(args.input_dir):
|
||||||
for filename in filenames:
|
for filename in filenames:
|
||||||
relpath = os.path.relpath(f'{root}/{filename}', start=args.input_dir)
|
rel_src = os.path.relpath(f'{root}/{filename}', start=args.input_dir)
|
||||||
abspath = os.path.abspath(f'{root}/{filename}')
|
|
||||||
# all non-markdown files are just copied over, the markdown
|
# all non-markdown files are just copied over, the markdown
|
||||||
# files are converted to html
|
# files are converted to html
|
||||||
if abspath.endswith('.md'):
|
if rel_src.endswith('.md'):
|
||||||
dstpath = os.path.abspath(f'{args.output_dir}/{relpath}')
|
rel_dst = rel_src
|
||||||
dstpath = dstpath[:-3] + '.html'
|
rel_dst = rel_dst[:-3] + '.html'
|
||||||
convertibles.append((abspath, dstpath))
|
convertibles.append((rel_src, rel_dst))
|
||||||
else:
|
else:
|
||||||
shutil.copy(abspath, f'{args.output_dir}/{relpath}')
|
shutil.copy(f'{args.input_dir}/{rel_src}', f'{args.output_dir}/{rel_src}')
|
||||||
for dirname in dirnames:
|
for dirname in dirnames:
|
||||||
# all directories are copied into the output directory
|
# all directories are copied into the output directory
|
||||||
path = os.path.relpath(f'{root}/{dirname}', start=args.input_dir)
|
path = os.path.relpath(f'{root}/{dirname}', start=args.input_dir)
|
||||||
os.makedirs(f'{args.output_dir}/{path}', exist_ok=True)
|
os.makedirs(f'{args.output_dir}/{path}', exist_ok=True)
|
||||||
|
|
||||||
convert_to_html(convertibles)
|
convert_to_html(convertibles, args.input_dir, args.output_dir)
|
||||||
|
|
||||||
|
|
||||||
def markdown_factory():
|
def markdown_factory():
|
||||||
@@ -111,7 +110,7 @@ def markdown_factory():
|
|||||||
return md
|
return md
|
||||||
|
|
||||||
|
|
||||||
def convert_to_html(convertibles):
|
def convert_to_html(convertibles, input_dir, output_dir):
|
||||||
|
|
||||||
env = Environment(
|
env = Environment(
|
||||||
loader=ChoiceLoader([
|
loader=ChoiceLoader([
|
||||||
@@ -122,12 +121,11 @@ def convert_to_html(convertibles):
|
|||||||
|
|
||||||
md = markdown_factory()
|
md = markdown_factory()
|
||||||
|
|
||||||
pages = []
|
|
||||||
articles = []
|
articles = []
|
||||||
|
|
||||||
for src, dst in convertibles:
|
for src, dst in convertibles:
|
||||||
logger.debug(f'Processing {src}')
|
logger.debug(f'Processing {src}')
|
||||||
with open(src, 'r') as fh:
|
with open(f'{input_dir}/{src}', 'r') as fh:
|
||||||
body = fh.read()
|
body = fh.read()
|
||||||
|
|
||||||
content, meta = convert_markdown(md, body)
|
content, meta = convert_markdown(md, body)
|
||||||
@@ -135,16 +133,11 @@ def convert_to_html(convertibles):
|
|||||||
context = dict(content=content)
|
context = dict(content=content)
|
||||||
context.update(meta)
|
context.update(meta)
|
||||||
|
|
||||||
# for now, treat all pages as articles
|
if meta and 'date' in meta:
|
||||||
if not meta:
|
|
||||||
pages.append((dst, context))
|
|
||||||
#template = env.get_template('page.html')
|
|
||||||
else:
|
|
||||||
articles.append((dst, context))
|
articles.append((dst, context))
|
||||||
#template = env.get_template('article.html')
|
|
||||||
template = env.get_template('article.html')
|
template = env.get_template('article.html')
|
||||||
result = template.render(context)
|
result = template.render(context)
|
||||||
with open(dst, 'w') as fh_dest:
|
with open(f'{output_dir}/{dst}', 'w') as fh_dest:
|
||||||
fh_dest.write(result)
|
fh_dest.write(result)
|
||||||
|
|
||||||
# generate feed
|
# generate feed
|
||||||
@@ -177,7 +170,7 @@ def convert_to_html(convertibles):
|
|||||||
ctx['archive'] = archive
|
ctx['archive'] = archive
|
||||||
template = env.get_template('archive.html')
|
template = env.get_template('archive.html')
|
||||||
result = template.render(ctx)
|
result = template.render(ctx)
|
||||||
with open('build/archive.html', 'w') as fh:
|
with open('build/index.html', 'w') as fh:
|
||||||
fh.write(result)
|
fh.write(result)
|
||||||
|
|
||||||
## generate tags
|
## generate tags
|
||||||
|
|||||||
@@ -9,17 +9,14 @@
|
|||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
<h1>Archive</h1>
|
|
||||||
|
|
||||||
{% for entry in archive %}
|
{% for entry in archive %}
|
||||||
|
|
||||||
{% if entry.title %}
|
<article>
|
||||||
<h1><a href="{{entry.dst}}">{{entry.title}}</a></h1>
|
<header>
|
||||||
{% endif %}
|
<time datetime="{{entry.date}}">{{entry.date.date()}}</time>
|
||||||
|
<h1><a href="{{entry.dst}}">{{entry.title}}</a></h1>
|
||||||
{% if entry.date %}
|
</header>
|
||||||
<p>Written on {{ entry.date.date() }}.</p>
|
</article>
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,6 @@
|
|||||||
<nav>
|
<nav>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="/">Blog</a></li>
|
<li><a href="/">Blog</a></li>
|
||||||
<li><a href="/archive.html">Archive</a></li>
|
|
||||||
<li><a href="/tags.html">Tags</a></li>
|
<li><a href="/tags.html">Tags</a></li>
|
||||||
<li><a href="https://venthur.de/pages/about-me.html">About Me</a></li>
|
<li><a href="https://venthur.de/pages/about-me.html">About Me</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
Reference in New Issue
Block a user