app: add rendering of markdown

Add rendering of markdown files stored in the pages directory using
templates in the templates directory.

Signed-off-by: Johannes Thumshirn <jth@kernel.org>
pull/1/head
Johannes Thumshirn 4 years ago
parent aa829dd3fb
commit 4e599be173

@ -5,10 +5,21 @@ from flask_flatpages import FlatPages
from datetime import datetime
app = Flask(__name__)
app.config['FLATPAGES_EXTENSION'] = '.md'
@app.route("/")
def hello_world():
return 'Hello, World!'
pages = FlatPages(app)
@app.route('/<path:path>.html')
def page(path):
page = pages.get_or_404(path)
return render_template('page.html', page=page)
@app.route('/')
def index():
posts = [p for p in pages if "date" in p.meta]
sorted_pages = sorted(posts, reverse=True, key=lambda page:
datetime.strptime(page.meta["date"], "%d %b %y"))
return render_template('bloghome.html', pages=sorted_pages)
if __name__ == '__main__':
app.run(host='0.0.0.0')

@ -0,0 +1,6 @@
title: Post title goes here
date: 25 Feb 21
author: Me
description: Hello World
Hello World

@ -0,0 +1,9 @@
{% extends "template.html" %}
{% block content %}
{% for page in pages %}
<a href="{{ page.path }}.html"><h2>{{ page.title }}</h2></a>
<p> {{ page.description }} </p>
<p> {{ page.date }} </p>
<hr>
{% endfor %}
{% endblock %}

@ -0,0 +1,6 @@
{% extends "template.html" %}
{% block content %}
<h1>{{ page.title }}</h1>
<p>{{page.html|safe }}</p>
<strong>{{ page.author }}</strong> {{ page.date }}
{% endblock %}

@ -0,0 +1,3 @@
<!DOCTYPE html>
{% block content %}
{% endblock %}
Loading…
Cancel
Save