Pelican plugin for piping shell output (stdout
) into site content (articles and pages), unlocking the versatility and flexibility of the shell for automated content generation and updates.
shell_pipe
relies on shell=True
flag within Python's [subprocess
] library, and this comes with risks.
Make sure you control the source of commands to avoid shell injection and arbitrary command execution.
Add shell_pipe
to PLUGINS
list:
PLUGIN_PATHS = ["pelican-plugins"]
PLUGINS = [
# ...
"shell_pipe",
# ...
]
Then, specify shell commands in-line in post & article sources:
Title: My Post
...
<!-- SHELL_BEGIN -->my-shell-command<!-- SHELL_END -->
See this example.
A budget-balance report was produced by hledger
, a command-line plaintext accounting program and written to the article's content.
In the post's source markdown:
<pre><!-- SHELL_BEGIN -->hledger bal -f ./.ledger/bus | head -n -2 | sed -z 's/\n/<br>/g'<!-- SHELL_END --></pre>
The post is updated to reflect the latest ledger each time the site is built: the hledger
command is executed with the latest input file ./ledger/bus
.