From b419cd5c31d11c9c733d0c76a9f3672861e22745 Mon Sep 17 00:00:00 2001 From: Francesco Luzzana Date: Sun, 13 Mar 2022 00:36:17 +0100 Subject: [PATCH] porting dump draft --- postit/__init__.py | 4 ++ postit/contents.json | 1 + postit/contents.py | 1 - postit/dump.py | 35 ++++++++++++++++++ postit/generate.py | 24 ++++++++++++ postit/static/css/postit.css | 71 ++++++++++++++++++++++++++++++++++++ postit/templates/postit.html | 25 +++++++++++++ setup.py | 2 +- 8 files changed, 161 insertions(+), 2 deletions(-) create mode 100644 postit/contents.json create mode 100644 postit/dump.py create mode 100644 postit/generate.py create mode 100644 postit/static/css/postit.css create mode 100644 postit/templates/postit.html diff --git a/postit/__init__.py b/postit/__init__.py index 3c6552e..071493d 100644 --- a/postit/__init__.py +++ b/postit/__init__.py @@ -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", "") ) diff --git a/postit/contents.json b/postit/contents.json new file mode 100644 index 0000000..0637a08 --- /dev/null +++ b/postit/contents.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/postit/contents.py b/postit/contents.py index 92be713..9430d18 100644 --- a/postit/contents.py +++ b/postit/contents.py @@ -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") diff --git a/postit/dump.py b/postit/dump.py new file mode 100644 index 0000000..3861661 --- /dev/null +++ b/postit/dump.py @@ -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)) diff --git a/postit/generate.py b/postit/generate.py new file mode 100644 index 0000000..fe6eeeb --- /dev/null +++ b/postit/generate.py @@ -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) diff --git a/postit/static/css/postit.css b/postit/static/css/postit.css new file mode 100644 index 0000000..a338c83 --- /dev/null +++ b/postit/static/css/postit.css @@ -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; +} diff --git a/postit/templates/postit.html b/postit/templates/postit.html new file mode 100644 index 0000000..f69a03d --- /dev/null +++ b/postit/templates/postit.html @@ -0,0 +1,25 @@ + + + + + + + Post it + + + +
+ {% for content in contents %} {% for i in range(12)%} +
+ {%if content['img'] %} + {{content['description']}} +
{{content['description']}}
+ {%else%} +

{{content['title']}}

+

{{content['description']}}

+ {%endif%} +
+ {%endfor%} {% endfor %} +
+ + diff --git a/setup.py b/setup.py index 07514b1..52c972d 100644 --- a/setup.py +++ b/setup.py @@ -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"], )