porting dump draft

master
km0 2 years ago
parent 3e68cace8e
commit b419cd5c31

@ -39,6 +39,10 @@ def create_app(test_config=None):
app.register_blueprint(contents.bp)
from . import generate
app.register_blueprint(generate.bp)
app.wsgi_app = prefix.PrefixMiddleware(
app.wsgi_app, prefix=os.environ.get("URL_PREFIX", "")
)

@ -1,5 +1,4 @@
import os
from shutil import rmtree
from flask import Blueprint, render_template, request, url_for
repo_url = os.environ.get("REPO_URL")

@ -0,0 +1,35 @@
import json
import frontmatter
import os
def dump():
# list all the folders
folders = [
name
for name in os.listdir()
if os.path.isdir(os.path.join("", name))
and not name.startswith(".")
and not name == "miri-the-leader"
]
print(folders)
contents = []
for folder in folders:
with open(f"{folder}/contents.md", "r") 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"],
}
else:
postit = {"title": metadata["title"], "description": content}
contents.append(postit)
with open("postit/contents.json", "w") as f:
f.write(json.dumps(contents))

@ -0,0 +1,24 @@
from flask import Blueprint, render_template
import json
from . import dump
bp = Blueprint("generate", __name__, url_prefix="/generate")
def generate():
pass
@bp.route("/")
def postit():
dump.dump()
return "hello"
# with open("contents.json", "r") as f:
# contents = json.load(f)
# return render_template("postit.html", contents=contents)

@ -0,0 +1,71 @@
@page {
size: A3;
margin: 5mm;
}
html,
body {
margin: 0;
}
* {
box-sizing: border-box;
}
.container {
font-size: 0;
}
.post-it {
position: relative;
vertical-align: middle;
display: inline-block;
width: 90mm;
height: 90mm;
border: 1px solid #ddd;
margin: 0;
font-family: Arial, Helvetica, sans-serif;
line-height: 1.4;
overflow: hidden;
text-overflow: ellipsis;
}
img {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
object-fit: cover;
z-index: 50;
}
.title {
font-size: 18px;
text-align: center;
margin: 4mm;
color: #aaa;
}
.description {
display: inline-block;
margin: 4mm;
font-size: 24px;
}
figcaption {
background-color: white;
font-size: 18px;
text-align: center;
display: inline-block;
position: absolute;
left: 50%;
bottom: 4mm;
transform: translate(-50%, 0);
z-index: 100;
}
a {
color: #ddd;
font-size: 12px;
}

@ -0,0 +1,25 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Post it</title>
<link rel="stylesheet" href="{{url_for('static', filename='css/postit.css')}}" />
</head>
<body>
<div class="container">
{% for content in contents %} {% for i in range(12)%}
<div class="post-it">
{%if content['img'] %}
<img src="{{content['img']}}" alt="{{content['description']}}" />
<figcaption>{{content['description']}}</figcaption>
{%else%}
<h2 class="title">{{content['title']}}</h2>
<p class="description">{{content['description']}}</p>
{%endif%}
</div>
{%endfor%} {% endfor %}
</div>
</body>
</html>

@ -6,5 +6,5 @@ setup(
packages=find_packages(),
include_package_data=True,
zip_safe=False,
install_requires=["flask", "python-dotenv"],
install_requires=["flask", "python-dotenv", "python-frontmatter"],
)

Loading…
Cancel
Save