Private
Public Access
1
0

added tags functionality

This commit is contained in:
2025-12-22 07:45:36 +01:00
parent 08cb8f4cc9
commit 1730c2e5fc
6 changed files with 90 additions and 26 deletions

43
app.py
View File

@@ -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('/<path:path>/')
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/<path:path>/') # 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/<string:tag_name>/')
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)
app.run(port=5001, debug=True)