-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Description
IMPORTANT NOTE: I am interested in doing the actual work here. This is thread is more to assess the interest level and get feedback.
SECOND IMPORTANT NOTE: I'm also happy to bring this discussion to Discourse. I'm not sure which venue should have priority for this.
Proposal
One of the things I like about Jekyll is its plugin system, which allows you to weave arbitrary Ruby logic into various points in the build pipeline. I think that the benefits of this for Hugo are pretty clear, and I've seen plugin proposals floated in past issues (#321) and community discussions.
It recently came to my attention in the Tools/libraries that can drive new Hugo features discussion that there's a Lua interpreter written in Go—actually more than one—that could, with some massaging, be used to enable Hugo users to run Lua scripts as part of the Hugo build pipeline.
Basic feature outline
This is obviously majorly up for discussion, but I envision something like this:
- Initially plugins would be disabled by default; you'd need to set an
--enablePluginsflag to use it - You could can a
pluginsdirectory to your Hugo project; at run time, Hugo would scan that directory for Lua files - For an initial implementation, you would name files based on where in the build pipeline you'd want the logic to run. A file called
prebuild.luawould run before Hugo does anything,prepage.luawould manipulate each page before Hugo does,postbuild.luawould run after Hugo is done with everything, and so on. - Eventually, you could use these scripts to add new templating functions, create project-specific Markdown extensions, etc. Anything you see here would conceivably be within reach.
Basic example
I'll provide a super simplistic example because I'm not yet super familiar with Lua. Imagine a postpage.lua script that runs after Hugo has processed a page. Imagine if for some reason you wanted to make the title of each page in the blog section lowercase:
-- plugins/postpage.lua
for i, page in ipairs(pages) do
if page.section == 'blog' then
page.title = string.lower(page.title)
end
endFeedback
Is this something that would be beneficial for Hugo? Does this seem like a vaguely reasonable approach? Worth the effort? Not the right direction for the project? Too much flexibility? Too much power?