Allow Jinja templating of scheduled topics (if it's safe)
Something that's fairly common to want to do in scheduled topics is have a way to include some "variables" that might vary each time the post is made. A common one is wanting to print the current date in a specific format, for cases like including the date in the title.
Jinja has some "sandboxing" capability for handling untrusted templates, but there isn't a lot of info about it, so it would need to be researched more deeply to see if it protects against everything that would be a concern. The core piece of it is SandboxedEnvironment
: https://jinja.palletsprojects.com/en/2.10.x/sandbox/#jinja2.sandbox.SandboxedEnvironment
It can be used something like this:
env = SandboxedEnvironment()
template = env.from_string("Weekly discussion thread - {{ date.strftime('%Y-%m-%d') }}")
title = template.render({"date": datetime.now()})
Which would set title
to something like Weekly discussion thread - 2019-10-16
.
So the idea would be to render the title and text as a Jinja template initially, then pass the result of that through the normal processing for titles and markdown.
Assuming this is all safe, there are lots of options for useful variables for the scheduled topics to be able to use in their title/text like a permalink to the previous topic, a counter for the number of previous posts in the series, and so on.