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 # list all the folders
path = "postit/contents" path = "postit/contents"
folders = [ 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 = [] contents = []
for folder in folders: 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()) metadata, body = frontmatter.parse(f.read())
for content in metadata["contents"]: for content in metadata["contents"]:
if type(content) == dict and content["img"]: if type(content) == dict and content["img"]:
postit = { postit = {
"title": metadata["title"], "title": metadata["title"],
"description": content["alt"], "description": content["alt"],
"img": content["img"], "img": content["img"],
"slug": folder,
} }
else: else:
postit = {"title": metadata["title"], "description": content} postit = {
"title": metadata["title"],
"description": content,
"slug": folder,
}
contents.append(postit) contents.append(postit)
with open("postit/contents.json", "w") as f: 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 import json
from . import dump from . import dump
bp = Blueprint("generate", __name__, url_prefix="/generate") bp = Blueprint(
"generate",
__name__,
url_prefix="/generate",
)
@bp.route("/") @bp.route("/")
@ -14,3 +18,8 @@ def postit():
contents = json.load(f) contents = json.load(f)
return render_template("postit.html", contents=contents) 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)%} {% for content in contents %} {% for i in range(12)%}
<div class="post-it"> <div class="post-it">
{%if content['img'] %} {%if content['img'] %}
<img src="{{content['img']}}" alt="{{content['description']}}" /> <img
src="{{content['slug']}}/{{content['img']}}"
alt="{{content['description']}}"
/>
<figcaption>{{content['description']}}</figcaption> <figcaption>{{content['description']}}</figcaption>
{%else%} {%else%}
<h2 class="title">{{content['title']}}</h2> <h2 class="title">{{content['title']}}</h2>

Loading…
Cancel
Save