Loads of boiler plating
Some checks failed
Build, Push, and Deploy to Nomad / docker-nomad (push) Has been cancelled

This commit is contained in:
Henrik Jess
2024-12-10 17:09:37 +01:00
parent e7fdfb4967
commit 492d933119
6 changed files with 172 additions and 158 deletions

16
app.py
View File

@@ -20,17 +20,29 @@ with open("mock_data.json") as file:
# Index route # Index route
@app.get("/", response_class=HTMLResponse) @app.get("/", response_class=HTMLResponse)
async def get_index(request: Request): async def get_index(request: Request):
return templates.TemplateResponse("index.html", {"request": request, "data": data}) return templates.TemplateResponse(
"index.html",
{"request": request, "data": data, "page_title": "Forside", "author": "Henrik"}
)
# Category route # Category route
@app.get("/category/{category_name}", response_class=HTMLResponse) @app.get("/category/{category_name}", response_class=HTMLResponse)
async def get_category(request: Request, category_name: str): async def get_category(request: Request, category_name: str):
# Find den korrekte kategori
category = next((cat for cat in data["categories"] if cat["path"] == category_name), None)
if category:
category_file = f"data/{category_name}/index.html" category_file = f"data/{category_name}/index.html"
if os.path.exists(category_file): if os.path.exists(category_file):
with open(category_file) as file: with open(category_file) as file:
category_content = file.read() category_content = file.read()
return templates.TemplateResponse( return templates.TemplateResponse(
"category.html", "category.html",
{"request": request, "category_name": category_name, "content": category_content} {
"request": request,
"data": data,
"page_title": category["name"],
"author": category["author"],
"content": category_content
},
) )
return HTMLResponse("Kategori ikke fundet", status_code=404) return HTMLResponse("Kategori ikke fundet", status_code=404)

View File

@@ -1,13 +1,13 @@
{ {
"categories": [ "categories": [
{"name": "SKAT", "path": "skat"}, {"name": "SKAT", "path": "skat", "author": "Henrik"},
{"name": "Skole", "path": "skole"}, {"name": "Skole", "path": "skole", "author": "Erika"},
{"name": "Bolig", "path": "bolig"}, {"name": "Bolig", "path": "bolig", "author": "Henrik"},
{"name": "Job", "path": "job"} {"name": "Job", "path": "job", "author": "Henrik"}
], ],
"favorites": [ "favorites": [
{"name": "SKAT", "image": "images/pic07.jpg", "description": "Farvorit Kategori"}, {"name": "SKAT", "image": "images/pic07.jpg", "description": "Favorit Kategori"},
{"name": "Skole", "image": "images/pic08.jpg", "description": "Skole info"}, {"name": "Skole", "image": "images/pic08.jpg", "description": "Skole information"},
{"name": "Bolig", "image": "images/pic09.jpg", "description": "Bolig detaljer"} {"name": "Bolig", "image": "images/pic09.jpg", "description": "Bolig detaljer"}
] ]
} }

View File

@@ -0,0 +1,48 @@
<!DOCTYPE HTML>
<html>
<head>
<title>{% block title %}PortugalFAQ{% endblock %}</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
<link rel="stylesheet" href="{{ url_for('static', path='css/main.css') }}" />
</head>
<body class="is-preload">
<!-- Wrapper -->
<div id="wrapper">
<!-- Main -->
<div id="main">
<div class="inner">
<!-- Header -->
<header id="header">
<a href="/" class="logo">
<strong>{{ page_title }}</strong> af {{ author }}
</a>
</header>
<!-- Content -->
{% block content %}{% endblock %}
</div>
</div>
<!-- Sidebar -->
<div id="sidebar">
<div class="inner">
{% include 'navigation.html' %}
<!-- Footer -->
<footer id="footer">
<p class="copyright">
&copy; Henriks lille hjørne: <a href="https://lifefaq.i80.dk">LifeFAQ</a>
</p>
</footer>
</div>
</div>
</div>
<!-- Scripts -->
<script src="{{ url_for('static', path='js/jquery.min.js') }}"></script>
<script src="{{ url_for('static', path='js/browser.min.js') }}"></script>
<script src="{{ url_for('static', path='js/breakpoints.min.js') }}"></script>
<script src="{{ url_for('static', path='js/util.js') }}"></script>
<script src="{{ url_for('static', path='js/main.js') }}"></script>
</body>
</html>

View File

@@ -1,14 +1,12 @@
<!DOCTYPE HTML> {% extends "base_template.html" %}
<html>
<head> {% block title %}{{ category_name }} - PortugalFAQ{% endblock %}
<title>{{ category_name }} - PortugalFAQ</title>
<link rel="stylesheet" href="{{ url_for('static', path='css/main.css') }}" /> {% block content %}
</head> <header class="main">
<body>
<div id="main">
<h1>{{ category_name }}</h1> <h1>{{ category_name }}</h1>
<div>{{ content | safe }}</div> </header>
<a href="/">Tilbage til forsiden</a> <div>
{{ content | safe }}
</div> </div>
</body> {% endblock %}
</html>

View File

@@ -1,26 +1,8 @@
<!DOCTYPE HTML> {% extends "base_template.html" %}
<html>
<head>
<title>PortugalFAQ - Henriks og Erikas lille side</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
<link rel="stylesheet" href="{{ url_for('static', path='css/main.css') }}" />
</head>
<body class="is-preload">
<!-- Wrapper -->
<div id="wrapper">
<!-- Main -->
<div id="main">
<div class="inner">
<!-- Header -->
<header id="header">
<a href="/" class="logo"><strong>Forside</strong> af Henrik</a>
<ul class="icons">
<li><a href="#" class="icon brands fa-facebook-f"><span class="label">Facebook</span></a></li>
</ul>
</header>
<!-- Content --> {% block title %}PortugalFAQ - Henriks og Erikas lille side{% endblock %}
{% block content %}
<section> <section>
<header class="main"> <header class="main">
<h1>Min Drøm om Portugal</h1> <h1>Min Drøm om Portugal</h1>
@@ -59,77 +41,4 @@
</p> </p>
<hr class="major" /> <hr class="major" />
</section> </section>
</div> {% endblock %}
</div>
<!-- Sidebar -->
<div id="sidebar">
<div class="inner">
<!-- Menu -->
<nav id="menu">
<header class="major">
<h2>Menu</h2>
</header>
<ul>
<li><a href="/">Forside</a></li>
<li>
<span class="opener">Kategorier</span>
<ul>
{% for category in data.categories %}
<li>
<a href="/category/{{ category.path }}">{{ category.name }}</a>
</li>
{% endfor %}
</ul>
</li>
<li><a href="#">Fotobog</a></li>
</ul>
</nav>
<!-- Highlights (favoritter) -->
<section>
<header class="major">
<h2>Highlights</h2>
</header>
<div class="mini-posts">
{% for favorite in data.favorites %}
<article>
<a href="#" class="image">
<img src="{{ url_for('static', path=favorite.image) }}" alt="{{ favorite.name }}" />
</a>
<p>{{ favorite.description }}</p>
</article>
{% endfor %}
</div>
</section>
<!-- Kontakt -->
<section>
<header class="major">
<h2>Kontakt os</h2>
</header>
<ul class="contact">
<li class="icon solid fa-envelope"><a href="#">henrik@i80.dk</a></li>
<li class="icon solid fa-phone">(+45) 60214417</li>
<li class="icon solid fa-home">Skovstræde 3<br />Stensved, 4773</li>
</ul>
</section>
<!-- Footer -->
<footer id="footer">
<p class="copyright">
&copy; Henriks lille hjørne: <a href="https://lifefaq.i80.dk">LifeFAQ</a>
</p>
</footer>
</div>
</div>
</div>
<!-- Scripts -->
<script src="{{ url_for('static', path='js/jquery.min.js') }}"></script>
<script src="{{ url_for('static', path='js/browser.min.js') }}"></script>
<script src="{{ url_for('static', path='js/breakpoints.min.js') }}"></script>
<script src="{{ url_for('static', path='js/util.js') }}"></script>
<script src="{{ url_for('static', path='js/main.js') }}"></script>
</body>
</html>

47
templates/navigation.html Normal file
View File

@@ -0,0 +1,47 @@
<!-- Navigation -->
<nav id="menu">
<header class="major">
<h2>Menu</h2>
</header>
<ul>
<li><a href="/">Forside</a></li>
<li>
<span class="opener">Kategorier</span>
<ul>
{% for category in data.categories %}
<li><a href="/category/{{ category.path }}">{{ category.name }}</a></li>
{% endfor %}
</ul>
</li>
<li><a href="#">Fotobog</a></li>
</ul>
</nav>
<!-- Highlights -->
<section>
<header class="major">
<h2>Highlights</h2>
</header>
<div class="mini-posts">
{% for favorite in data.favorites %}
<article>
<a href="#" class="image">
<img src="{{ url_for('static', path=favorite.image) }}" alt="{{ favorite.name }}" />
</a>
<p>{{ favorite.description }}</p>
</article>
{% endfor %}
</div>
</section>
<!-- Kontakt -->
<section>
<header class="major">
<h2>Kontakt os</h2>
</header>
<ul class="contact">
<li class="icon solid fa-envelope"><a href="#">henrik@i80.dk</a></li>
<li class="icon solid fa-phone">(+45) 60214417</li>
<li class="icon solid fa-home">Skovstræde 3<br />Stensved, 4773</li>
</ul>
</section>