Beacon (Beacon v0.4.0)
View SourceBeacon is a Content Management System for Phoenix LiveView.
Key features include:
- Rendering pages fast
- Reloading content at runtime
- Improved resource usage and scalability
- Integration with existing Phoenix applications
You can build virtually any type of website with Beacon, from a simple blog to a complex business site.
The following are the main APIs provided by Beacon. You can find more information in the documentation for each of these modules:
Beacon.Config
- configure your site(s)Beacon.Router
- mount site(s) into the router of your Phoenix applicationBeacon.Lifecycle
- inject custom logic into Beacon's lifecycle to change how pages are loaded, rendered, and moreBeacon.Content
- manage content such as layouts, pages, page variants, snippets, etc.Beacon.MediaLibrary
- upload images, videos, and documents that can be used in your contentBeacon.Test
- utilities for testing
Get started with your first site and check out the guides for more information.
Summary
Functions
@spec boot(Beacon.Config.t()) :: Supervisor.on_start_child() | {:error, :unreachable}
Boot a site.
It will restart the Site Supervisor if it's already running, otherwise it will start it in the main Beacon Supervisor.
This function is not necessary to be called in most cases, as Beacon will automatically boot all sites when it starts,
but in some cases where a site is started with the :manual
mode, you may want to call this function to boot the site
in the :live
mode to activate resource loading and PubSub events broadcasting.
Note that :live
sites that are not reachable will not be started,
see deployment topologies for more info.
Start Beacon
and a supervisor for each site, which will load all layouts, pages, components, and so on.
You must include the Beacon
supervisor on each application that you want it loaded. For a single Phoenix application
that would go in the children
list on the file lib/my_app/application.ex
. For Umbrella apps you can have
multiple apps running Beacon, suppose your project has 3 apps: core (regular app), blog (phoenix app), and marketing (phoenix app)
and you want to load one Beacon instance on each Phoenix app, so you would include Beacon
in the list of children
applications
in both blog and marketing applications with their own :sites
configuration.
Note that each Beacon instance may have multiple sites and each site loads in its own supervisor. That gives you the flexibility to plan your architecture from simple to complex environments. For example, you can have a single site serving all pages in a single Phoenix application or you can create a new site to isolate a landing page for a marketing campaign that may receive too much traffic.
See Beacon.Router
and Deployment Topologies for more information.
Options
Each site in :sites
may have its own configuration, see all available options at Beacon.Config.new/1
.
Examples
# runtime.exs
config :beacon,
my_site: [site: :my_site, repo: MyApp.Repo, endpoint: MyAppWeb.Endpoint, router: MyAppWeb.Router]
# lib/my_app/application.ex
def start(_type, _args) do
children = [
MyApp.Repo,
{Phoenix.PubSub, name: MyApp.PubSub},
{Beacon, [
sites: [
Application.fetch_env!(:beacon, :my_site)
]
]},
MyAppWeb.Endpoint
]
opts = [strategy: :one_for_one, name: MyApp.Supervisor]
Supervisor.start_link(children, opts)
end