credence_lib/render/catalog/
preparer.rs

1use super::{
2    super::{super::util::*, context::*, preparer::*},
3    annotation::*,
4    create::*,
5};
6
7use {axum::http::*, std::result::Result};
8
9//
10// Catalog
11//
12
13/// [RenderPreparer] for catalog.
14pub struct CatalogPreparer;
15
16impl RenderPreparer for CatalogPreparer {
17    async fn prepare<'own>(&self, context: &mut RenderContext<'own>) -> Result<(), StatusCode> {
18        if let Some(catalog) = context.rendered_page.annotations.other.get("catalog") {
19            let annotation = CatalogAnnotation::resolve(catalog);
20            let uri_path = uri_path_parent(&context.uri_path);
21            let directory = context.configuration.files.asset(&uri_path);
22            let catalog = create_catalog(annotation, &uri_path, directory, &context.configuration.render).await?;
23            context.variables.insert("catalog".into(), catalog.into());
24        }
25
26        Ok(())
27    }
28}