feat: add date of posts (fix #1)
This commit is contained in:
parent
a5e5153208
commit
b9b762d793
3 changed files with 20 additions and 6 deletions
|
@ -10,10 +10,10 @@ router = Blueprint(name, __name__)
|
|||
@router.route(f"/{name}/<int:file>")
|
||||
def read(file: int) -> str:
|
||||
"""read page"""
|
||||
content = None
|
||||
post = None
|
||||
if not Config.private or (Config.private and Config.is_logged()):
|
||||
filename = post_filename(file)
|
||||
content = get_post(filename)
|
||||
post = get_post(filename)
|
||||
|
||||
return render_template(
|
||||
"read.html",
|
||||
|
@ -21,8 +21,9 @@ def read(file: int) -> str:
|
|||
read_page=True,
|
||||
page_name=name,
|
||||
name=f"{file}.txt",
|
||||
file=content,
|
||||
file=post.content if post else None,
|
||||
post_file_id=post_file_id,
|
||||
date=post.creation_date if post else None,
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -17,7 +17,10 @@
|
|||
</main>
|
||||
|
||||
<footer>
|
||||
<p>
|
||||
{% if file %}posted at {{ date }} // {% endif %}
|
||||
<a href="/">back to index</a>
|
||||
</p>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
from os import listdir
|
||||
from os import path as os_path
|
||||
from os import remove as os_remove
|
||||
from time import ctime
|
||||
|
||||
from utils.config import Config
|
||||
|
||||
|
@ -27,7 +28,16 @@ def get_posts() -> list[str]:
|
|||
return posts
|
||||
|
||||
|
||||
def get_post(filename: str) -> str | None:
|
||||
class File:
|
||||
def __init__(self, content: str, cdate: str):
|
||||
# content
|
||||
self.content = content
|
||||
|
||||
# date of creation
|
||||
self.creation_date = cdate
|
||||
|
||||
|
||||
def get_post(filename: str) -> File | None:
|
||||
"""get a post"""
|
||||
try:
|
||||
open(filename)
|
||||
|
@ -35,7 +45,7 @@ def get_post(filename: str) -> str | None:
|
|||
return None
|
||||
else:
|
||||
with open(filename, "r") as reader:
|
||||
return reader.read()
|
||||
return File(reader.read(), ctime(os_path.getctime(filename)))
|
||||
|
||||
|
||||
def delete_post(filename: str) -> bool:
|
||||
|
|
Loading…
Reference in a new issue