View Source Beacon (Beacon v0.2.2)
Beacon is a Content Management System for Phoenix LiveView.
- Rendering pages fast.
- Reloading content at runtime.
- Reduced resources 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.
Following are the main APIs provided by Beacon. You can find out more information on the module documentation of each one of those modules:
Beacon.Config
- configuration of sites.Beacon.Router
- mount one or more sites into the router of your Phoenix application.Beacon.Lifecycle
- inject custom logic into Beacon lifecycle to change how pages are loaded an rendred, and more.Beacon.Content
- manage content as layouts, pages, page variants, snippets, and more.Beacon.MediaLibrary
- upload images, videos, and documents that can be used in your content.Beacon.Test
- testings utilities.
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()
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 active resource loading and PubSub events broadcasting.
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.
Options
Each site in :sites
may have its own configuration, see all available options at Beacon.Config.new/1
.
Examples
# config.exs or runtime.exs
config :my_app, Beacon,
sites: [
[site: :my_site, endpoint: MyAppWeb.Endpoint]
]
# lib/my_app/application.ex
def start(_type, _args) do
children = [
MyApp.Repo,
{Phoenix.PubSub, name: MyApp.PubSub},
{Beacon, Application.fetch_env!(:my_app, Beacon)}, # <- added Beacon here
MyAppWeb.Endpoint
]
opts = [strategy: :one_for_one, name: MyApp.Supervisor]
Supervisor.start_link(children, opts)
end