Avoid cloning so much for DynamicNodeFactory keys
This commit is contained in:
parent
175d429240
commit
50060a5f9d
@ -253,10 +253,10 @@ fn find_excerpt(post: &Post<HtmlContent>) -> Option<String> {
|
||||
struct MakeWritePosts {
|
||||
posts: DynamicInput<Option<Post<HtmlContent>>>,
|
||||
article_template: Input<Templates>,
|
||||
permalink_factory: DynamicNodeFactory<PathBuf, String>,
|
||||
output_path_factory: DynamicNodeFactory<PathBuf, PathBuf>,
|
||||
build_context_factory: DynamicNodeFactory<PathBuf, Context>,
|
||||
render_factory: DynamicNodeFactory<PathBuf, String>,
|
||||
permalink_factory: DynamicNodeFactory<NodeId, String>,
|
||||
output_path_factory: DynamicNodeFactory<NodeId, PathBuf>,
|
||||
build_context_factory: DynamicNodeFactory<NodeId, Context>,
|
||||
render_factory: DynamicNodeFactory<NodeId, String>,
|
||||
}
|
||||
impl MakeWritePosts {
|
||||
fn new(posts: DynamicInput<Option<Post<HtmlContent>>>, templates: Input<Templates>) -> Self {
|
||||
@ -274,16 +274,16 @@ impl DynamicRule for MakeWritePosts {
|
||||
type ChildOutput = String;
|
||||
fn evaluate(&mut self, ctx: &mut impl DynamicRuleContext) -> Vec<Input<Self::ChildOutput>> {
|
||||
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| {
|
||||
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(),
|
||||
@ -303,11 +303,12 @@ impl DynamicRule for MakeWritePosts {
|
||||
|
||||
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| {
|
||||
self.render_factory
|
||||
.add_node(ctx, post_input.node_id(), |ctx| {
|
||||
ctx.add_rule(RenderTemplate {
|
||||
name: "article",
|
||||
output_path: output_path.into(),
|
||||
|
@ -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<TagAndPosts>,
|
||||
#[skip_visit]
|
||||
templates: Input<Templates>,
|
||||
build_context_factory: DynamicNodeFactory<String, Context>,
|
||||
render_factory: DynamicNodeFactory<String, String>,
|
||||
build_context_factory: DynamicNodeFactory<NodeId, Context>,
|
||||
render_factory: DynamicNodeFactory<NodeId, String>,
|
||||
}
|
||||
impl MakeWriteTagPages {
|
||||
fn new(tags: DynamicInput<TagAndPosts>, templates: Input<Templates>) -> Self {
|
||||
@ -189,9 +190,9 @@ 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| {
|
||||
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(),
|
||||
@ -202,7 +203,8 @@ impl DynamicRule for MakeWriteTagPages {
|
||||
},
|
||||
))
|
||||
});
|
||||
self.render_factory.add_node(ctx, slug.clone(), |ctx| {
|
||||
self.render_factory
|
||||
.add_node(ctx, tag_input.node_id(), |ctx| {
|
||||
ctx.add_rule(RenderTemplate {
|
||||
name: "tag",
|
||||
output_path: format!("/{slug}/index.html").into(),
|
||||
|
@ -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<Templates>,
|
||||
|
@ -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<Option<Show>>,
|
||||
#[skip_visit]
|
||||
templates: Input<Templates>,
|
||||
build_context_factory: DynamicNodeFactory<String, Context>,
|
||||
render_factory: DynamicNodeFactory<String, String>,
|
||||
build_context_factory: DynamicNodeFactory<NodeId, Context>,
|
||||
render_factory: DynamicNodeFactory<NodeId, String>,
|
||||
}
|
||||
impl MakeRenderShows {
|
||||
fn new(shows: DynamicInput<Option<Show>>, templates: Input<Templates>) -> Self {
|
||||
@ -284,9 +285,9 @@ impl DynamicRule for MakeRenderShows {
|
||||
fn evaluate(&mut self, ctx: &mut impl DynamicRuleContext) -> Vec<Input<Self::ChildOutput>> {
|
||||
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| {
|
||||
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(),
|
||||
@ -297,7 +298,8 @@ impl DynamicRule for MakeRenderShows {
|
||||
},
|
||||
))
|
||||
});
|
||||
self.render_factory.add_node(ctx, show.slug.clone(), |ctx| {
|
||||
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(),
|
||||
|
Loading…
x
Reference in New Issue
Block a user