diff --git a/src/generator/posts.rs b/src/generator/posts.rs index 3ec21c5..effb886 100644 --- a/src/generator/posts.rs +++ b/src/generator/posts.rs @@ -253,10 +253,10 @@ fn find_excerpt(post: &Post) -> Option { struct MakeWritePosts { posts: DynamicInput>>, article_template: Input, - permalink_factory: DynamicNodeFactory, - output_path_factory: DynamicNodeFactory, - build_context_factory: DynamicNodeFactory, - render_factory: DynamicNodeFactory, + permalink_factory: DynamicNodeFactory, + output_path_factory: DynamicNodeFactory, + build_context_factory: DynamicNodeFactory, + render_factory: DynamicNodeFactory, } impl MakeWritePosts { fn new(posts: DynamicInput>>, templates: Input) -> Self { @@ -274,47 +274,48 @@ impl DynamicRule for MakeWritePosts { type ChildOutput = String; fn evaluate(&mut self, ctx: &mut impl DynamicRuleContext) -> Vec> { for post_input in self.posts.value().inputs.iter() { - if let Some(post) = post_input.value().as_ref() { + if post_input.value().is_some() { let permalink = self .permalink_factory - .add_node(ctx, post.path.clone(), |ctx| { + .add_node(ctx, post_input.node_id(), |ctx| { ctx.add_rule(PostPermalink(post_input.clone())) }); - let context = self - .build_context_factory - .add_node(ctx, post.path.clone(), |ctx| { - ctx.add_rule(BuildTemplateContext::new( - permalink.clone().into(), - post_input.clone(), - |post_opt, ctx| { - let post = post_opt.as_ref().unwrap(); - ctx.insert("metadata", &post.metadata); - ctx.insert( - "word_count", - &post - .word_count - .expect("post should have word count when rendering"), - ); - ctx.insert("content", post.content.html()); - }, - )) - }); + let context = + self.build_context_factory + .add_node(ctx, post_input.node_id(), |ctx| { + ctx.add_rule(BuildTemplateContext::new( + permalink.clone().into(), + post_input.clone(), + |post_opt, ctx| { + let post = post_opt.as_ref().unwrap(); + ctx.insert("metadata", &post.metadata); + ctx.insert( + "word_count", + &post + .word_count + .expect("post should have word count when rendering"), + ); + ctx.insert("content", post.content.html()); + }, + )) + }); let output_path = self.output_path_factory - .add_node(ctx, post.path.clone(), |ctx| { + .add_node(ctx, post_input.node_id(), |ctx| { ctx.add_rule(PostOutputPath(permalink)) }); - self.render_factory.add_node(ctx, post.path.clone(), |ctx| { - ctx.add_rule(RenderTemplate { - name: "article", - output_path: output_path.into(), - templates: self.article_template.clone(), - context: context.into(), - }) - }); + self.render_factory + .add_node(ctx, post_input.node_id(), |ctx| { + ctx.add_rule(RenderTemplate { + name: "article", + output_path: output_path.into(), + templates: self.article_template.clone(), + context: context.into(), + }) + }); } } self.permalink_factory.finalize_nodes(ctx); diff --git a/src/generator/tags.rs b/src/generator/tags.rs index ff820f4..50eab42 100644 --- a/src/generator/tags.rs +++ b/src/generator/tags.rs @@ -1,6 +1,7 @@ use std::collections::HashMap; use compute_graph::{ + NodeId, builder::GraphBuilder, input::{DynamicInput, Input, InputVisitable}, rule::{DynamicNodeFactory, DynamicRule, Rule}, @@ -167,8 +168,8 @@ struct MakeWriteTagPages { tags: DynamicInput, #[skip_visit] templates: Input, - build_context_factory: DynamicNodeFactory, - render_factory: DynamicNodeFactory, + build_context_factory: DynamicNodeFactory, + render_factory: DynamicNodeFactory, } impl MakeWriteTagPages { fn new(tags: DynamicInput, templates: Input) -> Self { @@ -189,27 +190,28 @@ impl DynamicRule for MakeWriteTagPages { for tag_input in self.tags.value().inputs.iter() { let tag_and_posts = tag_input.value(); let slug = &tag_and_posts.tag.slug; - let template_context = self - .build_context_factory - .add_node(ctx, slug.clone(), |ctx| { - ctx.add_rule(BuildTemplateContext::new( - format!("/{slug}/").into(), - tag_input.clone(), - |tag_and_posts, ctx| { - ctx.insert("tag_name", &tag_and_posts.tag.name); - ctx.insert("years", &tag_and_posts.posts.years()); - ctx.insert("posts_by_year", &tag_and_posts.posts.0); - }, - )) + let template_context = + self.build_context_factory + .add_node(ctx, tag_input.node_id(), |ctx| { + ctx.add_rule(BuildTemplateContext::new( + format!("/{slug}/").into(), + tag_input.clone(), + |tag_and_posts, ctx| { + ctx.insert("tag_name", &tag_and_posts.tag.name); + ctx.insert("years", &tag_and_posts.posts.years()); + ctx.insert("posts_by_year", &tag_and_posts.posts.0); + }, + )) + }); + self.render_factory + .add_node(ctx, tag_input.node_id(), |ctx| { + ctx.add_rule(RenderTemplate { + name: "tag", + output_path: format!("/{slug}/index.html").into(), + templates: self.templates.clone(), + context: template_context.into(), + }) }); - self.render_factory.add_node(ctx, slug.clone(), |ctx| { - ctx.add_rule(RenderTemplate { - name: "tag", - output_path: format!("/{slug}/index.html").into(), - templates: self.templates.clone(), - context: template_context.into(), - }) - }); } self.build_context_factory.finalize_nodes(ctx); self.render_factory.all_nodes(ctx) diff --git a/src/generator/tutorials.rs b/src/generator/tutorials.rs index f1d7f5d..8ec2f91 100644 --- a/src/generator/tutorials.rs +++ b/src/generator/tutorials.rs @@ -14,6 +14,7 @@ use super::util::slugify::slugify; use super::util::{content_path, from_frontmatter}; use super::{FileWatcher, templates::Templates}; +// tutorials are not actively maintained, so reading/parsing posts doesn't use the graph or watcher pub fn make_graph( builder: &mut GraphBuilder<(), Asynchronous>, default_template: Input, diff --git a/src/generator/tv.rs b/src/generator/tv.rs index eb60f89..850409a 100644 --- a/src/generator/tv.rs +++ b/src/generator/tv.rs @@ -7,6 +7,7 @@ use std::{ use anyhow::anyhow; use chrono::{DateTime, Local, NaiveDate}; use compute_graph::{ + NodeId, builder::GraphBuilder, input::{DynamicInput, Input, InputVisitable}, rule::{DynamicNodeFactory, DynamicRule, DynamicRuleContext, Rule}, @@ -266,8 +267,8 @@ struct MakeRenderShows { shows: DynamicInput>, #[skip_visit] templates: Input, - build_context_factory: DynamicNodeFactory, - render_factory: DynamicNodeFactory, + build_context_factory: DynamicNodeFactory, + render_factory: DynamicNodeFactory, } impl MakeRenderShows { fn new(shows: DynamicInput>, templates: Input) -> Self { @@ -284,27 +285,28 @@ impl DynamicRule for MakeRenderShows { fn evaluate(&mut self, ctx: &mut impl DynamicRuleContext) -> Vec> { for show_input in self.shows.value().inputs.iter() { if let Some(show) = show_input.value().as_ref() { - let context = self - .build_context_factory - .add_node(ctx, show.slug.clone(), |ctx| { - ctx.add_rule(BuildTemplateContext::new( - format!("/tv/{}/", show.slug).into(), - show_input.clone(), - |show, context| { - if let Some(show) = show { - context.insert("show", show); - } - }, - )) + let context = + self.build_context_factory + .add_node(ctx, show_input.node_id(), |ctx| { + ctx.add_rule(BuildTemplateContext::new( + format!("/tv/{}/", show.slug).into(), + show_input.clone(), + |show, context| { + if let Some(show) = show { + context.insert("show", show); + } + }, + )) + }); + self.render_factory + .add_node(ctx, show_input.node_id(), |ctx| { + ctx.add_rule(RenderTemplate { + name: "show", + output_path: format!("/tv/{}/index.html", show.slug).into(), + templates: self.templates.clone(), + context: context.into(), + }) }); - self.render_factory.add_node(ctx, show.slug.clone(), |ctx| { - ctx.add_rule(RenderTemplate { - name: "show", - output_path: format!("/tv/{}/index.html", show.slug).into(), - templates: self.templates.clone(), - context: context.into(), - }) - }); } } self.build_context_factory.finalize_nodes(ctx);