ContentApp class

The root component for building a content-driven site.

ContentApp builds the top-level Router for the site. The provided RouteLoaders are used to load the full set of routes for the site. A RouteLoader then builds a Page for each route based on the resolved PageConfig.

For a single page, the following steps are taken:

  1. The page is created by one of the provided RouteLoaders.
  2. The page's configuration is resolved by the provided ConfigResolver based on its route.
  3. The page's frontmatter is parsed and additional data is loaded by the configured DataLoaders.
  4. The page's content is pre-processed by the configured TemplateEngine.
  5. The page's content is parsed by one of the configured PageParsers.
  6. The parsed content is further processed by the configured PageExtensions.
  7. The processed content is rendered using the configured CustomComponents ans wrapped in a Content component.
  8. The content is wrapped in a PageLayout and gets applied the configured ContentTheme.
  9. The result is rendered to HTML.

Page creation (steps 1 and 2) is always done eagerly at startup for all pages.

Page loading (step 3) happens either lazily or eagerly.

  • In lazy mode (default), pages are loaded on-demand when they are requested. This is useful for large sites when serving locally or when running in server mode, as it avoids the overhead of loading all pages at startup.
  • In eager mode, all pages are loaded at startup. This is needed when a page may depend on other pages, such as when rendering a collection of sub-pages. Read PageContext.pages for more information.

Page rendering (steps 4 to 9) is always done on-demand when a page is requested. In eager mode, this waits for all pages to be loaded before rendering the requested page.

Constructors

ContentApp({String directory = 'content', bool eagerlyLoadAllPages = false, bool enableFrontmatter = true, String dataDirectory = 'content/_data', TemplateEngine? templateEngine, List<PageParser> parsers = const [], List<PageExtension> extensions = const [], List<CustomComponent> components = const [], List<PageLayout> layouts = const [], ContentTheme? theme, bool debugPrint = false})
Creates a basic ContentApp that loads pages from the filesystem and applies the same configuration to all pages.
ContentApp.custom({required List<RouteLoader> loaders, bool eagerlyLoadAllPages = false, ConfigResolver configResolver = _defaultConfigResolver, Component routerBuilder(List<List<RouteBase>> routes) = _defaultRouterBuilder})
Creates a ContentApp.

Properties

configResolver → ConfigResolver
final
eagerlyLoadAllPages bool
final
hashCode int
The hash code for this object.
no setterinherited
key → Key?
Controls how one component replaces another component in the tree.
finalinherited
loaders List<RouteLoader>
final
routerBuilder → Component Function(List<List<RouteBase>> routes)
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

build(BuildContext context) Future<Component>
createElement() → Element
Inflates this configuration to a concrete instance.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited