beacon icon indicating copy to clipboard operation
beacon copied to clipboard

[Proposal] Plugin System

Open leandrocp opened this issue 9 months ago • 0 comments

Allow users to pack config, functions, and data to extend Beacon.

Enable plugins in your site config:

plugins: [MyBlogPlugin]

And the plugin implements Beacon.Plugin:

defmodule MyBlogPlugin do
  @behaviour Beacon.Plugin

  @impl true
  def config do
    %Beacon.Config{
      extra_page_fields: [MyBlogPlugin.PageFields.Type]
      # ... and more if needed
    }
  end

  @impl true
  def install(opts) do
    # install script to seed data / bootstrap content like components
    # eg: insert components
  end

  # provide extra functions to be used on sites
  def latest_blog_posts(limit) do
    Beacon.Content.list_published_pages(...)
  end
end

defmodule MyBlogPlugin.PageFields.Type do
  @behaviour Beacon.Content.PageField
  # ... omitted 
end
  • With this approach we can extend Beacon as necessary by adding new callbacks to inject code into different levels of its lifecycle.
  • Config can only be merged, ie: can't remove values.

leandrocp avatar May 23 '24 13:05 leandrocp