draft: modifications
All checks were successful
ci/woodpecker/push/publish Pipeline was successful

* automatically load all routes
* local configuration
* rename public to static directory
* wip: add basic login page
* route based on filename
* page name based on route
* add login button
* add dummy icon
This commit is contained in:
Mylloon 2023-12-21 21:17:56 +01:00
parent 76f77fdadd
commit 236fd36219
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
12 changed files with 115 additions and 21 deletions

View file

@ -1,7 +1,11 @@
from flask import Flask
from routes.index import router as index
from routes.read import router as read
from glob import glob
app = Flask(__name__, static_url_path="/", static_folder="public")
app.register_blueprint(index, url_prefix="/")
app.register_blueprint(read, url_prefix="/read")
from flask import Flask
app = Flask(__name__, static_url_path="/")
# Import all routes
for file in glob("src/routes/*.py"):
module = file.replace("/", ".").split(".")[-2]
exec(f"from routes.{module} import router as {module}")
exec(f"app.register_blueprint({module})")

22
src/config.py Normal file
View file

@ -0,0 +1,22 @@
from os import environ as envar
VAR_USERNAME = "TD_USERNAME"
class User:
"""user informations"""
name = envar[VAR_USERNAME] if VAR_USERNAME in envar else None
class Config:
"""app configuration"""
# App name
name = "txtdiary"
# App description
description = "Personal diary page"
# User
user = User

View file

@ -1,3 +0,0 @@
html {
font-family: "Courier New", Courier, monospace;
}

View file

@ -2,12 +2,14 @@
Index page with a list of posts.
"""
from config import Config
from flask import Blueprint, render_template
router = Blueprint("index", __name__)
name = __name__.split(".")[-1]
router = Blueprint(name, __name__)
@router.route("")
@router.route("/")
def index() -> str:
"""Index page"""
return render_template("index.html")
return render_template("index.html", config=Config, page_name=name)

22
src/routes/login.py Normal file
View file

@ -0,0 +1,22 @@
"""
Login page to an account.
"""
from config import Config
from flask import Blueprint, jsonify, render_template
from werkzeug import Response
name = __name__.split(".")[-1]
router = Blueprint(name, __name__)
@router.route(f"/{name}")
def login() -> str:
"""Login page"""
return render_template("login.html", config=Config, page_name=name)
@router.route(f"/{name}", methods=["POST"])
def check() -> Response:
"""Login logic"""
return jsonify("{}")

View file

@ -2,12 +2,14 @@
Read a specific post.
"""
from config import Config
from flask import Blueprint, render_template
router = Blueprint("read", __name__)
name = __name__.split(".")[-1]
router = Blueprint(name, __name__)
@router.route("")
@router.route(f"/{name}")
def read() -> str:
"""Read page"""
return render_template("read.html")
return render_template("read.html", config=Config, page_name=name)

15
src/static/css/style.css Normal file
View file

@ -0,0 +1,15 @@
html {
font-family: "Courier New", Courier, monospace;
}
/* Align title with button */
header {
display: flex;
align-items: center;
}
/* SVG centered on the line */
header svg {
margin-left: 0.5em;
vertical-align: middle;
}

View file

@ -2,11 +2,17 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="title" content="txtdiary" />
<meta name="title" content="{{ page_name }}" />
<meta name="description" content="{{ config.description }}" />
<meta property="og:title" content="txtdiary" />
<meta property="og:title" content="{{ page_name }}" />
<meta property="og:description" content="{{ config.description }}" />
<meta property="og:type" content="website" />
<meta property="twitter:title" content="txtdiary" />
<meta property="twitter:title" content="{{ page_name }}" />
<meta property="twitter:description" content="{{ config.description }}" />
<link rel="icon" href="data:," />
<link rel="stylesheet" href="/css/style.css" />
<title>{{ page_name }} - {{ config.name }}</title>

View file

@ -1 +1,12 @@
<header></header>
<header>
<h1>txtdiary{{ " of " + config.user.name if config.user.name else "" }}</h1>
<form action="/login" method="post">
<a href="/login">
<svg width="30px" fill="none" viewBox="0 0 24 24">
<path
stroke="#000"
d="M5 21a7 7 0 1 1 14 0M16 7a4 4 0 1 1-8 0 4 4 0 0 1 8 0Z"
/></svg
></a>
</form>
</header>

View file

@ -2,7 +2,6 @@
<html lang="en">
<head>
{% include "head.html" %}
<title>Index</title>
</head>
<!-- TODO: icon of login in -->
{% include "header.html" %}

15
src/templates/login.html Normal file
View file

@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
{% include "head.html" %}
</head>
{% include "header.html" %}
<body>
<p>Welcome to the login page</p>
<!-- TODO: Form -->
<form action="/login" method="post">
<button type="submit">Se connecter</button>
</form>
</body>
</html>

View file

@ -2,7 +2,6 @@
<html lang="en">
<head>
{% include "head.html" %}
<title>Read</title>
</head>
{% include "header.html" %}
<body>