Added page for browsing posts

This commit is contained in:
vanten-s 2023-09-06 11:00:25 +02:00
parent e88f66200a
commit 3f40fdb3b3
Signed by: vanten-s
GPG key ID: DE3060396884D3F2
5 changed files with 162 additions and 13 deletions

1
.gitignore vendored
View file

@ -1,3 +1,4 @@
venv/
log.txt
src/rss.xml
__pycache__/

25
main.py
View file

@ -1,15 +1,36 @@
import frmWrk.website as website
import feed_generator
import markdown
import pathlib
from time import sleep
article_base_html = ""
with open("src/article.html") as article_html:
article_base_html = article_html.read()
articles_base_html = ""
with open("src/articles.html") as articles_html:
articles_base_html = articles_html.read()
def article_list():
article_paths = (pathlib.Path.cwd() / "feed_articles").glob("[0-9]*")
article_paths_sorted = sorted(article_paths, key=lambda x: x.name, reverse=True)
metadatas = [feed_generator.convert_markdown_to_html(path)[1] for path in article_paths_sorted]
elements = ['<li><a href="articles.html?{guid}">{title} ({guid})</a></li>'.format(title=metadata["title"][0], guid=metadata["guid"][0]) for metadata in metadatas]
return articles_base_html.format(elements="\n".join(elements))
def article(path):
if not "?" in path:
return article_list()
article_name = path.split("?")[1]
article_html = feed_generator.convert_markdown_to_html(pathlib.Path("feed_articles") / article_name)
return article_html[0]
return article_base_html.format(body=article_html[0])
if __name__ == "__main__":
webserver = website.WebServer("", 3000, "./src", overwrites={"/articles.html": article})
webserver.start()

61
src/article.html Normal file
View file

@ -0,0 +1,61 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Article</title>
<link rel="stylesheet" href="assets/main.css">
<link rel="stylesheet" href="assets/fontAwesome/css/fontawesome.css">
<link rel="stylesheet" href="assets/fontAwesome/css/brands.css">
<link rel="stylesheet" href="assets/fontAwesome/css/solid.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/hack-font/3.3.0/web/hack.min.css">
<link rel="icon" href="/assets/favicon.png">
</head>
<body>
<div id="body">
{body}
</div>
<ul class="navbar">
<li>
<a href="mailto:vanten-s@vanten-s.com">
<span class="popup">Mail</span>
<i class="fa-solid fa-envelope fa"></i>
</a>
</li>
<li>
<a rel="me" href="https://kolektiva.social/@vanten_s">
<span class="popup">Mastodon</span>
<i class="fa-brands fa-mastodon fa"></i>
</a>
</li>
<li>
<a href="key.asc">
<span class="popup">GPG Key</span>
<i class="fa-solid fa-key"></i>
</a>
</li>
<li>
<a href="https://matrix.to/#/@vanten-s:matrix.org">
<span class="popup">Matrix</span>
<i class="fa-solid fa-comment"></i>
</a>
</li>
<li>
<a href="https://forgejo.vanten-s.com/vanten-s">
<span class="popup">Forgejo</span>
<i class="fa-brands fa-git-alt"></i>
</a>
</li>
<li>
<a href="rss.xml">
<span class="popup">RSS Feed</span>
<i class="fa-solid fa-rss"></i>
</a>
</li>
<li>
<a href="articles.html">
<span class="popup">Posts</span>
<i class="fa-solid fa-blog"></i>
</a>
</li>
</ul>
</body>
</html>

60
src/articles.html Normal file
View file

@ -0,0 +1,60 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Articles</title>
<link rel="stylesheet" href="assets/main.css">
<link rel="stylesheet" href="assets/fontAwesome/css/fontawesome.css">
<link rel="stylesheet" href="assets/fontAwesome/css/brands.css">
<link rel="stylesheet" href="assets/fontAwesome/css/solid.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/hack-font/3.3.0/web/hack.min.css">
<link rel="icon" href="/assets/favicon.png">
</head>
<body>
<h1>Posts</h1>
{elements}
<ul class="navbar">
<li>
<a href="mailto:vanten-s@vanten-s.com">
<span class="popup">Mail</span>
<i class="fa-solid fa-envelope fa"></i>
</a>
</li>
<li>
<a rel="me" href="https://kolektiva.social/@vanten_s">
<span class="popup">Mastodon</span>
<i class="fa-brands fa-mastodon fa"></i>
</a>
</li>
<li>
<a href="key.asc">
<span class="popup">GPG Key</span>
<i class="fa-solid fa-key"></i>
</a>
</li>
<li>
<a href="https://matrix.to/#/@vanten-s:matrix.org">
<span class="popup">Matrix</span>
<i class="fa-solid fa-comment"></i>
</a>
</li>
<li>
<a href="https://forgejo.vanten-s.com/vanten-s">
<span class="popup">Forgejo</span>
<i class="fa-brands fa-git-alt"></i>
</a>
</li>
<li>
<a href="rss.xml">
<span class="popup">RSS Feed</span>
<i class="fa-solid fa-rss"></i>
</a>
</li>
<li>
<a href="articles.html">
<span class="popup">Posts</span>
<i class="fa-solid fa-blog"></i>
</a>
</li>
</ul>
</body>
</html>

View file

@ -78,6 +78,12 @@
<i class="fa-solid fa-rss"></i>
</a>
</li>
<li>
<a href="articles.html">
<span class="popup">Posts</span>
<i class="fa-solid fa-blog"></i>
</a>
</li>
</ul>
</body>
</html>