render method

Future<Component> render()

Renders the page.

This performs the following steps in order:

  1. Parses the frontmatter if enableFrontmatter is true.
  2. Loads additional data using the provided dataLoaders.
  3. Preprocesses the content if a templateEngine is provided.
  4. If enableRawOutput is true, outputs the content as raw text and skips further processing. Else continues with 5.
  5. Parses the nodes of the page using one of the parsers.
  6. Processes the nodes by applying the provided extensions.
  7. Builds the Content component from the processed nodes.
  8. Builds the layout for the page using one of the layouts.
  9. Wraps the layout in the provided theme.

Implementation

Future<Component> render() async {
  parseFrontmatter();
  await loadData();
  return AsyncBuilder(
    builder: (context) async {
      await renderTemplate(context.pages);

      if (kGenerateMode) {
        if (data.page['sitemap'] case final sitemap?) {
          context.setHeader('jaspr-sitemap-data', jsonEncode(sitemap));
        }
      }

      if (InheritedSecondaryOutput.of(context) case final secondaryOutput?) {
        return secondaryOutput.builder(this);
      }

      if (config.rawOutputPattern?.matchAsPrefix(path) != null) {
        context.setHeader('Content-Type', getContentType());
        context.setStatusCode(200, responseBody: content);
        return Component.fragment([]);
      }

      return await build();
    },
  );
}