made flask server able to read markdown files for posts
This commit is contained in:
1 parent
ad3a3f17ff
commit
5c4d0dfa6f
11 files changed
+155
-44
No files matched your search
+25
@@ -0,0 +1,25 @@
|
||||
import markdown
|
||||
import datetime
|
||||
|
||||
class Post:
|
||||
|
||||
category : str
|
||||
author : str
|
||||
date : datetime.datetime
|
||||
body : str
|
||||
file : str
|
||||
|
||||
def __init__(self, file_path):
|
||||
self.file = file_path
|
||||
|
||||
with open(file_path, 'r') as file:
|
||||
lines = file.readlines()
|
||||
|
||||
self.category = lines[1].split(":")[1].strip()
|
||||
self.author = lines[2].split(":")[1].strip()
|
||||
|
||||
date = lines[3].split(":")[1].strip()
|
||||
self.date = datetime.datetime.strptime(date, "%d-%m-%Y")
|
||||
|
||||
self.body = markdown.markdown(''.join(lines[6:]))
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
# Metadata
|
||||
category: category
|
||||
author: author
|
||||
date: date
|
||||
|
||||
# POST
|
||||
## TITLE
|
||||
### DATE OR SUBTITLE
|
||||
POST TEXT
|
||||
Binary file not shown.
@@ -0,0 +1,113 @@
|
||||
/* Global Settings */
|
||||
@font-face {
|
||||
font-family: ibmplexmono;
|
||||
src: url(./IBMPlexMono-Regular.woff) format('woff');
|
||||
}
|
||||
|
||||
|
||||
body {
|
||||
/* font-family: 'Courier New', Courier, monospace; */
|
||||
font-family: ibmplexmono;
|
||||
}
|
||||
|
||||
a {
|
||||
color: black;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
color: hotpink;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* Other */
|
||||
|
||||
.header {
|
||||
text-align: center;
|
||||
|
||||
margin: 10pt;
|
||||
|
||||
border-style: solid;
|
||||
border-color: #1E2022;
|
||||
background-color: #F0F5F9;
|
||||
border-radius: 5pt;
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
}
|
||||
|
||||
.container {
|
||||
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
|
||||
border-style: solid;
|
||||
border-color: #1E2022;
|
||||
background-color: #F0F5F9;
|
||||
}
|
||||
|
||||
.sidebar {
|
||||
order: 1;
|
||||
float: left;
|
||||
|
||||
padding: 20pt;
|
||||
padding-bottom: 25%;
|
||||
|
||||
margin: 15pt;
|
||||
|
||||
border-style: solid;
|
||||
border-radius: 10px;
|
||||
border-color: #1E2022;
|
||||
background-color: #C9D6DF;
|
||||
|
||||
opacity: 0.9;
|
||||
|
||||
/* Text Settings */
|
||||
font-weight: bold;
|
||||
line-height: 30pt;
|
||||
}
|
||||
|
||||
.sidebar a {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
|
||||
.dlog {
|
||||
order: 2;
|
||||
flex: 3;
|
||||
/* text-align: center; */
|
||||
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
padding: 10pt;
|
||||
margin: 15pt;
|
||||
margin-left: 15%;
|
||||
margin-right: 15%;
|
||||
|
||||
border-style: solid;
|
||||
border-radius: 10px;
|
||||
border-color: #1E2022;
|
||||
background-color: #C9D6DF;
|
||||
}
|
||||
|
||||
.post {
|
||||
/* opacity: 0.9; */
|
||||
|
||||
border: 2px solid #52616B;
|
||||
border-radius: 10px;
|
||||
|
||||
padding: 10pt;
|
||||
|
||||
margin: 10pt;
|
||||
margin-left: 20pt;
|
||||
margin-right: 20pt;
|
||||
|
||||
background-color: #C9D6DF;
|
||||
}
|
||||
|
||||
.post p {
|
||||
text-indent: 3em;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<header>
|
||||
<link rel="shortcut icon" href="index_favicon.ico">
|
||||
<link rel="stylesheet" href="index_style.css">
|
||||
<title>0x01fe.net</title>
|
||||
</header>
|
||||
<body>
|
||||
<div class="header">
|
||||
<h1>0x01fe.net</h1>
|
||||
<h4>Catchy Right‽</h4>
|
||||
</div>
|
||||
<div class="container">
|
||||
<!-- Sidebar -->
|
||||
<div class="sidebar">
|
||||
<a href="./">Home</a><br>
|
||||
<a href="">Media</a><br>
|
||||
<a href="">Programming</a><br>
|
||||
<a href="">About</a>
|
||||
</div>
|
||||
|
||||
<!-- Main Page -->
|
||||
<!-- Get it? D-Log? Like digital log? -->
|
||||
<div class="dlog">
|
||||
{% for post in posts %}
|
||||
<div class="post">{{ post|safe }}</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,53 @@
|
||||
import glob
|
||||
import configparser
|
||||
|
||||
import flask
|
||||
|
||||
from post import Post
|
||||
|
||||
app = flask.Flask(__name__, static_url_path='', static_folder='static')
|
||||
|
||||
config = configparser.ConfigParser()
|
||||
config.read("config.ini")
|
||||
|
||||
POSTS_FOLDER = config['POSTS']['POSTS_FOLDER']
|
||||
|
||||
def get_posts() -> list[Post]:
|
||||
post_files= glob.glob(f'{POSTS_FOLDER}/*')
|
||||
post_files.remove(f'{POSTS_FOLDER}\\POST_TEMPLATE.md')
|
||||
|
||||
posts: list[Post] = []
|
||||
for post_file in post_files:
|
||||
post = Post(post_file)
|
||||
|
||||
posts.append(post)
|
||||
|
||||
# Order Posts by Date
|
||||
ordered_posts = []
|
||||
for i in range(len(posts)):
|
||||
|
||||
most_recent = posts[0]
|
||||
for p in posts:
|
||||
if p.date < most_recent.date:
|
||||
most_recent = p
|
||||
|
||||
ordered_posts.append(most_recent)
|
||||
posts.remove(most_recent)
|
||||
|
||||
return reversed(ordered_posts)
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
|
||||
# Get posts
|
||||
posts = get_posts()
|
||||
|
||||
post_bodies = []
|
||||
for post in posts:
|
||||
post_bodies.append(post.body)
|
||||
|
||||
return flask.render_template('index.html', posts=post_bodies)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run()
|
||||
Reference in new issue
Block a user