Skip to content

Feature: Jekyll-style plugins using Lua #5510

@lucperkins

Description

@lucperkins

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 --enablePlugins flag to use it
  • You could can a plugins directory 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.lua would run before Hugo does anything, prepage.lua would manipulate each page before Hugo does, postbuild.lua would 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
end

Feedback

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions