diff options
author | mjfernez <mjfernez@gmail.com> | 2021-10-14 20:14:53 -0400 |
---|---|---|
committer | mjfernez <mjfernez@gmail.com> | 2021-10-14 20:14:53 -0400 |
commit | c583a69362f86fcc8e1b35a45a06dd8377d6308f (patch) | |
tree | 30609b89aa2781c95fc5c04ff96db3ab063e16e7 /views.py | |
parent | f7668243b7a55d1f69d508b3baaf891055715f63 (diff) | |
download | ezcms-c583a69362f86fcc8e1b35a45a06dd8377d6308f.tar.gz |
Adds RSS auto-generation for files in 'site'
This commit adds rss_generator.py which contains the main logic for
indexing the site directory and generating a feed on startup. It serves
as a sort of ad-hoc database which is accessed when /feed.xml is
requested.
Also corrects various typos, README nonsense, and expands the config
options for RSS. Instances of './templates/site' have been replaced with
the general BASE_DIR variable in the siteconfig.
Diffstat (limited to 'views.py')
-rw-r--r-- | views.py | 23 |
1 files changed, 19 insertions, 4 deletions
@@ -4,7 +4,7 @@ browsing to certain pages """ import os from flask import request, send_from_directory, abort -from flask import render_template, render_template_string +from flask import render_template, render_template_string, make_response from siteconfig import siteconfig from server import app, cache from view_functions import default_context, index_dir, is_hidden_path @@ -19,6 +19,8 @@ CONTENT_BLOCK = ( @app.route("/") @app.route("/site") +@app.route("/site/home.html") +@app.route("/site/index.html") @cache.cached() def home(): """ @@ -48,7 +50,7 @@ def render_file(path): """ if is_hidden_path(path): abort(404) - abs_path = "./templates/site/" + path + abs_path = siteconfig.BASE_DIR + path context = default_context() context.update( { @@ -68,7 +70,7 @@ def render_file(path): else: # not an html file, so don't render it return send_from_directory( - 'templates/site/', + siteconfig.BASE_DIR, path, mimetype=siteconfig.MIMETYPES.get( f".{ path.split('.')[-1] }", @@ -101,7 +103,7 @@ def send_file_from_site(path): as with `render_file`, send the raw file to the user """ return send_from_directory( - 'templates/site/', + siteconfig.BASE_DIR, path, mimetype=siteconfig.MIMETYPES.get( f".{ path.split('.')[-1] }", siteconfig.DEFAULT_MIMETYPE @@ -122,3 +124,16 @@ def send_file_from_static(path): f".{ path.split('.')[-1] }", siteconfig.DEFAULT_MIMETYPE ), ) + + +@app.route("/feed.xml") +@cache.cached() +def render_rss_feed(): + context = { + 'config': siteconfig.rss_channel_config, + 'items': app.config['RSS_CHANNEL'], + } + feed = render_template("feed.xml", **context) + response = make_response(feed) + response.headers['Content-Type'] = siteconfig.MIMETYPES.get(".xml") + return response |