Add JS page info

This commit is contained in:
Yusur 2021-03-14 22:50:49 +01:00
parent 2b7d990bb9
commit 0394e4b0d4
5 changed files with 25 additions and 5 deletions

15
app.py
View file

@ -76,6 +76,21 @@ class Page(BaseModel):
(PageTag.name << (old_tags - new_tags))).execute() (PageTag.name << (old_tags - new_tags))).execute()
for tag in (new_tags - old_tags): for tag in (new_tags - old_tags):
PageTag.create(page=self, name=tag) PageTag.create(page=self, name=tag)
def js_info(self):
latest = self.latest
return dict(
id=self.id,
url=self.url,
title=self.title,
is_redirect=self.is_redirect,
touched=self.touched.timestamp(),
latest=dict(
id=latest.id if latest else None,
length=latest.length,
pub_date=latest.pub_date.timestamp() if latest and latest.pub_date else None
),
tags=[x.name for x in self.tags]
)
@property @property
def prop(self): def prop(self):
return PagePropertyDict(self) return PagePropertyDict(self)

View file

@ -23,11 +23,12 @@ body{font-family:sans-serif}
.nl-desc{font-size:0.9em;opacity:.75;font-family:serif} .nl-desc{font-size:0.9em;opacity:.75;font-family:serif}
.nl-new{margin:6px 0 12px 0;display:flex;justify-content:start} .nl-new{margin:6px 0 12px 0;display:flex;justify-content:start}
.nl-new > a{margin-right:12px} .nl-new > a{margin-right:12px}
input[type="text"]{border:0;border-bottom:3px solid #ccc;font:inherit;color:#181818;background-color:transparent} input{border:0;border-bottom:3px solid #ccc;font:inherit;color:#181818;background-color:transparent}
input[type="text"]:focus{color:black;border-bottom-color:#09f} input:focus{color:black;border-bottom-color:#09f}
input[type="text"].error{border-bottom-color:#ff1800} input.error{border-bottom-color:#ff1800}
.submit-primary{color:white;background-color:#37b92e;font-family:inherit;border:1px solid #37b92e;font-size:1.2em;height:2em;min-width:8em;border-radius:12px;display:inline-block} input[type="submit"],input[type="reset"],input[type="button"],button{font-family:inherit;border-radius:12px;border:1px solid #ccc;display:inline-block}
.submit-secondary{color:black;background-color:white;font-family:inherit;border:1px solid #809980;font-size:1.2em;height:2em;min-width:8em;border-radius:12px;display:inline-block} .submit-primary{color:white;background-color:#37b92e;font-family:inherit;border:1px solid #37b92e;font-size:1.2em;height:2em;min-width:8em}
.submit-secondary{color:black;background-color:white;font-family:inherit;border:1px solid #809980;font-size:1.2em;height:2em;min-width:8em}
.flash{background-color:#fff2b4;padding:12px;border-radius:4px;border:1px #ffe660 solid} .flash{background-color:#fff2b4;padding:12px;border-radius:4px;border:1px #ffe660 solid}
.page-tags p{display:inline-block} .page-tags p{display:inline-block}
.page-tags ul{padding:0;margin:0;list-style:none;display:inline-block} .page-tags ul{padding:0;margin:0;list-style:none;display:inline-block}

View file

@ -8,6 +8,7 @@
<link rel="stylesheet" href="/static/style.css"> <link rel="stylesheet" href="/static/style.css">
<!-- material icons --> <!-- material icons -->
<link rel="stylesheet" href="https://cdn.sakuragasaki46.local/common/material-icons.css"> <link rel="stylesheet" href="https://cdn.sakuragasaki46.local/common/material-icons.css">
{% block json_info %}{% endblock %}
</head> </head>
<body{% if request.cookies.get('dark') == '1' %} class="dark"{% endif %}> <body{% if request.cookies.get('dark') == '1' %} class="dark"{% endif %}>
<div id="__top"></div> <div id="__top"></div>

View file

@ -31,5 +31,6 @@
<h2>{{ T('latest-uploads') }}</h2> <h2>{{ T('latest-uploads') }}</h2>
{# TODO security flaw; find a way to do this in a more safe manner! #}
{{ gallery|safe }} {{ gallery|safe }}
{% endblock %} {% endblock %}

View file

@ -2,6 +2,8 @@
{% block title %}{{ p.title }} - {{ app_name }}{% endblock %} {% block title %}{{ p.title }} - {{ app_name }}{% endblock %}
{% block json_info %}<script>window.page_info={{ p.js_info()|tojson|safe }};</script>{% endblock %}
{% block content %} {% block content %}
<h1>{{ p.title }}</h1> <h1>{{ p.title }}</h1>