feat/render file
This commit is contained in:
parent
b496c95f10
commit
98e5a26514
2 changed files with 162 additions and 0 deletions
|
@ -16,6 +16,88 @@ def initdb(drop):
|
|||
db.create_all()
|
||||
click.echo('Initialized database.')
|
||||
|
||||
@app.cli.command()
|
||||
def renderfile():
|
||||
"""render toot"""
|
||||
from BDSM.models import Toot
|
||||
from BDSM.views import process_toot
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
|
||||
head = '''<!Doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<style>
|
||||
body {
|
||||
margin: auto !important;
|
||||
padding: 5px;
|
||||
max-width: 580px;
|
||||
font-size: 14px;
|
||||
font-family: Helvetica, Arial, sans-serif;
|
||||
}
|
||||
.toot {
|
||||
padding-top: 10px;
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
.status {
|
||||
border: 1px solid #393f4f;
|
||||
}
|
||||
.toot-media{
|
||||
width: 100%;
|
||||
}
|
||||
.meta .time {
|
||||
float: right;
|
||||
text-decoration: underline;
|
||||
color: #606984;
|
||||
}
|
||||
.emojione {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
margin: -3px 0 0;
|
||||
}
|
||||
.emojione:hover {
|
||||
z-index: 11;
|
||||
/* Scale up 2.3 times */
|
||||
transform: scale(2.3);
|
||||
/* shadows around image edges */
|
||||
filter: drop-shadow(0 0 1px #282c37);
|
||||
}
|
||||
.icon-bar {
|
||||
display: block ruby;
|
||||
}
|
||||
.icon-bar span {
|
||||
padding-right: 10px;
|
||||
}
|
||||
|
||||
</style>
|
||||
</head>
|
||||
</body>
|
||||
'''
|
||||
def render_toot(toot_id):
|
||||
_toot = []
|
||||
toot = Toot.query.get(toot_id)
|
||||
|
||||
if toot == None:
|
||||
return "None"
|
||||
|
||||
_toot.append(toot)
|
||||
_toot = process_toot(_toot)
|
||||
env = Environment(loader=FileSystemLoader("./BDSM/templates"))
|
||||
jinja_template = env.get_template("toot.html")
|
||||
template_string = jinja_template.render(toots=_toot)
|
||||
return template_string
|
||||
|
||||
def _render(input_file):
|
||||
env = Environment(loader=FileSystemLoader("./"))
|
||||
jinja_template = env.get_template(input_file)
|
||||
jinja_template.globals.update(render_toot=render_toot)
|
||||
template_string = jinja_template.render()
|
||||
|
||||
with open('./output.html', 'w') as f:
|
||||
f.write(head + template_string + '</body></html>')
|
||||
|
||||
_render("input.txt")
|
||||
print("Done?")
|
||||
|
||||
@app.cli.command()
|
||||
def graball():
|
||||
"""Grab all toots context"""
|
||||
|
|
80
BDSM/templates/toot.html
Normal file
80
BDSM/templates/toot.html
Normal file
|
@ -0,0 +1,80 @@
|
|||
{% for toot in toots recursive%}
|
||||
<div class="toot">
|
||||
<div class="status">
|
||||
<div class="meta">
|
||||
{% if toot.is_reblog%}
|
||||
<small><span>转嘟了<i class="fa-solid fa-retweet"></i></span></small>
|
||||
{% endif %}
|
||||
<strong><span class ="username">{{ toot.acct }}</span></strong>
|
||||
<a href="{{ toot.url }}" target="_blank"
|
||||
rel="noopener noreferrer">
|
||||
<span class="time">
|
||||
{% if toot.visibility == "public"%}
|
||||
<span class="visibility-icon">🌐</span>
|
||||
{% elif toot.visibility == "unlisted"%}
|
||||
<span class="visibility-icon">🔓</span>
|
||||
{% elif toot.visibility == "private"%}
|
||||
<span class="visibility-icon">🔒</span>
|
||||
{% elif toot.visibility == "direct"%}
|
||||
<span class="visibility-icon">✉️</i></span>
|
||||
{% endif %}
|
||||
<time>{{ toot.created_at }}
|
||||
{% if toot.edited_at != None %}
|
||||
<strong>*</strong>
|
||||
{% endif %}
|
||||
</time></span></a>
|
||||
</div>
|
||||
<div class="content">
|
||||
{% if toot.spoiler_text != "" %}
|
||||
<strong><i>CW: {{toot.spoiler_text|safe}}</i></strong>
|
||||
{% endif %}
|
||||
{{ toot.content|safe }}
|
||||
</div>
|
||||
|
||||
<div class="toot-media">
|
||||
<div class="row">
|
||||
{% if toot.medias %}
|
||||
|
||||
{% for media in toot.medias%}
|
||||
{% if media.type == 'image' %}
|
||||
<div class="col-lg-6">
|
||||
<a class="media-gallery__item-thumbnail"
|
||||
href="{{ media.url }}" target="_blank" rel="noopener noreferrer" data-lightbox="{{ toot.id }}" data-title="{{ media.description }}">
|
||||
<img src="{{ media.url }}" class="toot-media" alt="{{ media.description }}"/></a>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endfor%}
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="icon-bar">
|
||||
<div class="info-bar">
|
||||
{% if toot.replies_count %}
|
||||
<span>↩️ {{ toot.replies_count }}</span>
|
||||
{% else %}
|
||||
<span>↩️ {{ toot.replies_count }}</span>
|
||||
{% endif %}
|
||||
|
||||
{% if toot.reblogged %}
|
||||
<span>🔄 {{ toot.reblogs_count}}</span>
|
||||
{% else %}
|
||||
<span>🔄 {{ toot.reblogs_count}}</span>
|
||||
{% endif %}
|
||||
|
||||
{% if toot.favourited %}
|
||||
<span>⭐ {{ toot.favourites_count }}</span>
|
||||
{% else %}
|
||||
<span>⭐ {{ toot.favourites_count }}</span>
|
||||
{% endif %}
|
||||
|
||||
{% if toot.bookmarked %}
|
||||
<span>🔖</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{%- if toot.reply -%}
|
||||
<div class="reply">{{ loop(toot.reply) }}</div>
|
||||
{%- endif %}
|
||||
{% endfor %}
|
Loading…
Reference in a new issue