Compare commits

..

3 commits

Author SHA1 Message Date
608e85bc93
date in index #9
All checks were successful
Publish latest version / build (push) Successful in 50s
this could lead to a offset of one day max since we don't use the tz
2024-11-17 14:45:56 +01:00
ad7922c68f
format imports 2024-11-17 14:39:08 +01:00
a79ce635d1
clickable badge 2024-11-17 14:16:17 +01:00
8 changed files with 31 additions and 9 deletions

View file

@ -1,6 +1,6 @@
# txtdiary
![status-badge](https://git.mylloon.fr/Anri/txtdiary/badges/workflows/publish.yml/badge.svg)
[![status-badge](https://git.mylloon.fr/Anri/txtdiary/badges/workflows/publish.yml/badge.svg)](https://git.mylloon.fr/Anri/txtdiary/actions?workflow=publish.yml)
personal diary with txt style, can be private!

View file

@ -3,6 +3,7 @@ from glob import glob
from os import mkdir, urandom
from flask import Flask, session
from utils.config import Config
app = Flask(__name__, static_url_path="/")

View file

@ -1,8 +1,9 @@
from flask import Blueprint, flash, redirect, render_template, request
from utils.config import Config
from utils.misc import create_post, fresh_file_id, get_posts
from werkzeug import Response
from utils.config import Config
from utils.misc import create_post, fresh_file_id, get_post_cdate, get_posts
name = __name__.split(".")[-1]
router = Blueprint(name, __name__)
@ -12,7 +13,18 @@ def index() -> str:
"""index page"""
posts = []
if not Config.private or (Config.private and Config.is_logged()):
posts = [p.split("/")[-1][:-4] for p in get_posts()]
for p in get_posts():
def titleify(s):
return s.split("/")[-1]
def linkify(s):
return ".".join(titleify(s).split(".")[:-1])
def datify(s):
return s[:-14] + " " + s[-4:]
posts.append((linkify(p), titleify(p), datify(get_post_cdate(p))))
return render_template(
"index.html",

View file

@ -1,7 +1,8 @@
from flask import Blueprint, flash, redirect, render_template, request
from utils.config import Config
from werkzeug import Response
from utils.config import Config
name = __name__.split(".")[-1]
router = Blueprint(name, __name__)

View file

@ -1,7 +1,8 @@
from flask import Blueprint, flash, redirect, render_template
from werkzeug import Response
from utils.config import Config
from utils.misc import delete_post, get_post, post_file_id, post_filename
from werkzeug import Response
name = __name__.split(".")[-1]
router = Blueprint(name, __name__)

View file

@ -1,7 +1,8 @@
from flask import Blueprint, jsonify, request, session
from utils.config import Config
from werkzeug import Response
from utils.config import Config
name = __name__.split(".")[-1]
router = Blueprint(name, __name__)

View file

@ -19,7 +19,8 @@
<ul>
{% for p in posts: %}
<li>
<a href="{{ config.sanitized_base() }}/read/{{ p }}">{{ p }}.txt</a>
<a href="{{ config.sanitized_base() }}/read/{{ p[0] }}">{{ p[1] }}</a>
({{ p[2] }})
</li>
{% endfor %}
</ul>

View file

@ -6,6 +6,7 @@ from time import ctime
from flask import session
from pytz import timezone
from utils.config import Config
@ -50,7 +51,11 @@ def get_post(filename: str) -> File | None:
return None
else:
with open(filename, "r") as reader:
return File(reader.read(), ctime(os_path.getmtime(filename)))
return File(reader.read(), get_post_cdate(filename))
def get_post_cdate(filename: str) -> str:
return ctime(os_path.getmtime(filename))
def delete_post(filename: str) -> bool: