cobalt.rs icon indicating copy to clipboard operation
cobalt.rs copied to clipboard

RFC: User-defined plugins

Open epage opened this issue 4 years ago • 5 comments

We'd have a new folder _plugins full of FILLER that we load.

Plugins include

  • Liquid tags, blocks, and filters
    • For tags and blocks, we just parse all parameters as named or position arguments without any validating logic (ie Vec<(Option<KString>, Value)>) until end of %}. We then pass that to the plugin to deal with
    • Plugins can just accept these as arguments
    • Plugins can turn these into a form of syntax like treating one of the elements as a keyword

Open questions

  • What language?
    • Lua is well know
    • Rhai would integrate well with Rust
    • Dyon and Gluon are from the game community
  • Plugin per file or multiple in a file?
    • If multiple, whats the idiomatic way to do it for the given language?

epage avatar Jul 07 '20 02:07 epage

Can you develop what kind of plugins?

On the language, I'd vote for Rhai, because Rust. And I have bad past experience with Lua (I don't know if it's still true, but the "if not marked as local, it's global) made me freak out a lot

Geobert avatar Jul 07 '20 16:07 Geobert

Can you develop what kind of plugins?

So far the only ones I've thought are are listed:

Liquid tags, blocks, and filters

So say you want a custom shortcode plugin ({% youtube id="foobar" %}). In python (since I don't know the embedded languages) it'd look like

def plugins():
    return {
        "tag": {
            "youtube": youtube_shortcode,
        }
    }

def youtube_shortcode(arguments):
    args = {}
    for name, value in arguments:
        if name is None:
            raise ValueError("Only named arguments are supported")
        elif name in ["id"]:
            args[name] = value
        else:
            raise ValueError("Unsupported argument: %s" % name)
    ... do formatting ...
    return full_url

epage avatar Jul 07 '20 16:07 epage

I see :) (Even if for shortcodes, I have something in antimoine to load custom shortcode, so they're easier to write, but maybe plugins is a better way?)

Geobert avatar Jul 08 '20 07:07 Geobert

I see :) (Even if for shortcodes, I have something in antimoine to load custom shortcode, so they're easier to write, but maybe plugins is a better way?)

Shortcodes was a trivial example that can be solved in multiple ways. Other extensibilty ideas include filter-blocks and macros

https://github.com/cobalt-org/liquid-rust/issues/321 https://github.com/cobalt-org/liquid-rust/issues/322

epage avatar Jul 08 '20 13:07 epage

If plugins are supported, having the ability to write custom generators in Rust would be nice.

I'd love to port https://github.com/avillafiorita/jekyll-datapage_gen/ and https://github.com/captn3m0/jekyll-sqlite/ for eg.

captn3m0 avatar May 08 '23 12:05 captn3m0