diff --git a/app.py b/app.py index 9f05a80..4d96a82 100644 --- a/app.py +++ b/app.py @@ -1,29 +1,46 @@ from flask import Flask, render_template from flask_flatpages import FlatPages -DEBUG = True -FLATPAGES_AUTO_RELOAD = DEBUG -FLATPAGES_EXTENSION = '.md' - app = Flask(__name__) -app.config.from_object(__name__) + +# Consolidate Configs +app.config.update( + FLATPAGES_AUTO_RELOAD = True, + FLATPAGES_EXTENSION = '.md', + FLATPAGES_MARKDOWN_EXTENSIONS = ['fenced_code', 'tables'] +) + pages = FlatPages(app) -FLATPAGES_MARKDOWN_EXTENSIONS = ['fenced_code', 'tables'] -app.config['FLATPAGES_MARKDOWN_EXTENSIONS'] = FLATPAGES_MARKDOWN_EXTENSIONS @app.route('/') def index(): + # Sort posts by date metadata posts = sorted(pages, key=lambda p: p.meta.get('date'), reverse=True) return render_template('index.html', posts=posts) -@app.route('//') -def post(path): - page = pages.get_or_404(path) - return render_template('post.html', page=page) - @app.route('/about') def about(): return render_template('about.html') + +@app.route('/post//') # Adding /post/ prefix helps organize URLs +def post(path): + page = pages.get_or_404(path) + return render_template('post.html', page=page) + +@app.route('/tag//') +def tag(tag_name): + tagged_pages = [p for p in pages if tag_name in p.meta.get('tags', [])] + return render_template('tag.html', pages=tagged_pages, tag_name=tag_name) + +@app.context_processor +def inject_tags(): + all_tags = set() + for page in pages: + t = page.meta.get('tags', []) + if isinstance(t, list): + all_tags.update(t) + return dict(all_cloud_tags=sorted(list(all_tags))) + if __name__ == "__main__": - app.run(port=5001) \ No newline at end of file + app.run(port=5001, debug=True) \ No newline at end of file diff --git a/templates/about.html b/templates/about.html index a8b1ef2..783192a 100644 --- a/templates/about.html +++ b/templates/about.html @@ -4,5 +4,5 @@

What is this site?

-I write articles about Arduino, STM32 and self-hosting. The articles are short and conceptual. It is not tutorials but more high level descriptions and general guidelines for reproducing the various things i tinker with. +I write articles about Arduino, STM32 and Self-hosting. The articles are short and conceptual. It is not tutorials but more high level descriptions and general guidelines for reproducing the various things i tinker with. {% endblock %} \ No newline at end of file diff --git a/templates/base.html b/templates/base.html index c04b9cf..4e71286 100644 --- a/templates/base.html +++ b/templates/base.html @@ -10,6 +10,7 @@ +
- {% block content %}{% endblock %} -
+
+
+ {% block content %}{% endblock %} +
+ +
+
- - - + + + + \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index f8df270..e6d66ca 100644 --- a/templates/index.html +++ b/templates/index.html @@ -2,17 +2,26 @@ {% block content %}
-

I write about Self-hosting, Arduino, STM32 and various tech stupidity.

+

I write about Self-hosting, Arduino, STM32.

{% for post in posts %} -
-

{{ post.title }}

- {{ post.date }} -

{{ post.meta.get('description', 'Read more...') }}

-

{{ post.meta.get('tag', 'no tag') }}

-
+
+

+ + {{ post.title }} + +

+ {{ post.date }} +

{{ post.meta.get('description', 'Read more...') }}

+ +
+ {% for tag in post.meta.get('tags', []) %} + #{{ tag }} + {% endfor %} +
+
{% else %}

No posts yet. Time to write something!

{% endfor %} diff --git a/templates/post.html b/templates/post.html index faec6f0..b0e86a7 100644 --- a/templates/post.html +++ b/templates/post.html @@ -5,5 +5,10 @@

{{ page.date }}

{{ page.html|safe }}
+ {% for t in page.tags %} + {{ t }}{% if not loop.last %}, {% endif %} + {% endfor %} + + {% endblock %} \ No newline at end of file diff --git a/templates/tag.html b/templates/tag.html new file mode 100644 index 0000000..58749f2 --- /dev/null +++ b/templates/tag.html @@ -0,0 +1,16 @@ +{% extends "base.html" %} + +{% block content %} +

Posts tagged with "{{ tag_name }}"

+ +
+ {% for p in pages %} + + {% else %} +

No posts found with this tag.

+ {% endfor %} +
+{% endblock %} \ No newline at end of file