static contents from the submodule

master
km0 2 years ago
parent b358330992
commit b02cbf8732

File diff suppressed because one or more lines are too long

@ -7,23 +7,29 @@ def dump():
# list all the folders
path = "postit/contents"
folders = [
f.path for f in os.scandir(path) if f.is_dir() and f.name != "miri-the-leader"
f.name for f in os.scandir(path) if f.is_dir() and f.name != "miri-the-leader"
]
contents = []
for folder in folders:
with open(f"{folder}/contents.md", "r", encoding="utf8") as f:
with open(f"{path}/{folder}/contents.md", "r", encoding="utf8") as f:
metadata, body = frontmatter.parse(f.read())
for content in metadata["contents"]:
if type(content) == dict and content["img"]:
postit = {
"title": metadata["title"],
"description": content["alt"],
"img": content["img"],
"slug": folder,
}
else:
postit = {"title": metadata["title"], "description": content}
postit = {
"title": metadata["title"],
"description": content,
"slug": folder,
}
contents.append(postit)
with open("postit/contents.json", "w") as f:

@ -1,8 +1,12 @@
from flask import Blueprint, render_template
from flask import Blueprint, render_template, send_from_directory
import json
from . import dump
bp = Blueprint("generate", __name__, url_prefix="/generate")
bp = Blueprint(
"generate",
__name__,
url_prefix="/generate",
)
@bp.route("/")
@ -14,3 +18,8 @@ def postit():
contents = json.load(f)
return render_template("postit.html", contents=contents)
@bp.route("/<slug>/<filename>/")
def send_static(slug=None, filename=None):
return send_from_directory(f"/postit/contents/{slug}", filename)

@ -12,7 +12,10 @@
{% for content in contents %} {% for i in range(12)%}
<div class="post-it">
{%if content['img'] %}
<img src="{{content['img']}}" alt="{{content['description']}}" />
<img
src="{{content['slug']}}/{{content['img']}}"
alt="{{content['description']}}"
/>
<figcaption>{{content['description']}}</figcaption>
{%else%}
<h2 class="title">{{content['title']}}</h2>

Loading…
Cancel
Save