diff --git a/discord_rss_bot/main.py b/discord_rss_bot/main.py index abcf83e..21baaed 100644 --- a/discord_rss_bot/main.py +++ b/discord_rss_bot/main.py @@ -1,11 +1,11 @@ import enum import sys +from functools import cache import uvicorn from apscheduler.schedulers.background import BackgroundScheduler from fastapi import FastAPI, Form, Request -from fastapi.responses import HTMLResponse -from fastapi.staticfiles import StaticFiles +from fastapi.responses import FileResponse, HTMLResponse from fastapi.templating import Jinja2Templates from reader import FeedExistsError @@ -13,10 +13,16 @@ from discord_rss_bot.feeds import _check_feed from discord_rss_bot.settings import logger, read_settings_file, reader app = FastAPI() -app.mount("/static", StaticFiles(directory="static"), name="static") templates = Jinja2Templates(directory="templates") +@cache +@app.get("/favicon.ico", include_in_schema=False) +async def favicon(): + """Return favicon.""" + return FileResponse('static/favicon.ico') + + @app.post("/check", response_class=HTMLResponse) def check_feed(request: Request, feed_url: str = Form()): """Check all feeds""" @@ -178,5 +184,20 @@ async def create_feed(feed_url: str = Form(), webhook_dropdown: str = Form()): return {"feed_url": str(feed_url), "status": "added", "webhook": webhook_url} +@app.get("/add", response_class=HTMLResponse) +def get_add(request: Request): + """ + This is the root of the website. + + Args: + request: + + Returns: + HTMLResponse: The HTML response. + """ + context = make_context_index(request) + return templates.TemplateResponse("add.html", context) + + if __name__ == "__main__": uvicorn.run("main:app", log_level="debug") diff --git a/discord_rss_bot/static/favicon.ico b/discord_rss_bot/static/favicon.ico new file mode 100644 index 0000000..9e57c4b Binary files /dev/null and b/discord_rss_bot/static/favicon.ico differ diff --git a/discord_rss_bot/templates/add.html b/discord_rss_bot/templates/add.html new file mode 100644 index 0000000..54d13a8 --- /dev/null +++ b/discord_rss_bot/templates/add.html @@ -0,0 +1,24 @@ +{% extends "base.html" %} +{% block title %}Index{% endblock %} +{% block content %} +
+ + +
+ + +
+ +
+ +
+
+{% endblock %} \ No newline at end of file diff --git a/discord_rss_bot/templates/base.html b/discord_rss_bot/templates/base.html new file mode 100644 index 0000000..7c5b3e3 --- /dev/null +++ b/discord_rss_bot/templates/base.html @@ -0,0 +1,24 @@ + + + + {% block head %} + + + + RSS - {% block title %}{% endblock %} + {% endblock %} + + + +
{% block content %}{% endblock %}
+ + + \ No newline at end of file diff --git a/discord_rss_bot/templates/feed.html b/discord_rss_bot/templates/feed.html index fe0fb11..31db085 100644 --- a/discord_rss_bot/templates/feed.html +++ b/discord_rss_bot/templates/feed.html @@ -1,33 +1,28 @@ - - - - - Feed - - -URL: {{ feed.url }}
-Title: {{ feed.title }}
-Updated: {{ feed.updated }}
-Link: {{ feed.link }}
-Author: {{ feed.author }}
-Subtitle: {{ feed.subtitle }}
-Version: {{ feed.version }}
-User title: {{ feed.user_title }}
-Added on: {{ feed.added }}
-Last update: {{ feed.last_update }}
-Last exception: {{ feed.last_exception }}
-Updates enabled: {{ feed.updates_enabled }}
+{% extends "base.html" %} +{% block title %}Feed{% endblock %} +{% block content %} + URL: {{ feed.url }}
+ Title: {{ feed.title }}
+ Updated: {{ feed.updated }}
+ Link: {{ feed.link }}
+ Author: {{ feed.author }}
+ Subtitle: {{ feed.subtitle }}
+ Version: {{ feed.version }}
+ User title: {{ feed.user_title }}
+ Added on: {{ feed.added }}
+ Last update: {{ feed.last_update }}
+ Last exception: {{ feed.last_exception }}
+ Updates enabled: {{ feed.updates_enabled }}
-
- -
+
+ +
-
- -
- - \ No newline at end of file +
+ +
+{% endblock %} \ No newline at end of file diff --git a/discord_rss_bot/templates/index.html b/discord_rss_bot/templates/index.html index 56303ab..c445852 100644 --- a/discord_rss_bot/templates/index.html +++ b/discord_rss_bot/templates/index.html @@ -1,73 +1,49 @@ - - - - - Index - - - - - -
- - - - -
- - -{% for tag in tags %} - - {{ tag }} - -{% endfor %} - +{% extends "base.html" %} +{% block title %}Index{% endblock %} +{% block content %} + + {% for tag in tags %} + {{ tag }} + {% endfor %} + - -
- - - - - \ No newline at end of file +{% endblock %} \ No newline at end of file