render method
Renders the page.
This performs the following steps in order:
- Parses the frontmatter if
enableFrontmatteris true. - Loads additional data using the provided
dataLoaders. - Preprocesses the content if a
templateEngineis provided. - If
enableRawOutputis true, outputs the content as raw text and skips further processing. Else continues with 5. - Parses the nodes of the page using one of the
parsers. - Processes the nodes by applying the provided
extensions. - Builds the
Contentcomponent from the processed nodes. - Builds the layout for the page using one of the
layouts. - 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();
},
);
}