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 {
|
struct MakeWritePosts {
|
||||||
posts: DynamicInput<Option<Post<HtmlContent>>>,
|
posts: DynamicInput<Option<Post<HtmlContent>>>,
|
||||||
article_template: Input<Templates>,
|
article_template: Input<Templates>,
|
||||||
permalink_factory: DynamicNodeFactory<PathBuf, String>,
|
permalink_factory: DynamicNodeFactory<NodeId, String>,
|
||||||
output_path_factory: DynamicNodeFactory<PathBuf, PathBuf>,
|
output_path_factory: DynamicNodeFactory<NodeId, PathBuf>,
|
||||||
build_context_factory: DynamicNodeFactory<PathBuf, Context>,
|
build_context_factory: DynamicNodeFactory<NodeId, Context>,
|
||||||
render_factory: DynamicNodeFactory<PathBuf, String>,
|
render_factory: DynamicNodeFactory<NodeId, String>,
|
||||||
}
|
}
|
||||||
impl MakeWritePosts {
|
impl MakeWritePosts {
|
||||||
fn new(posts: DynamicInput<Option<Post<HtmlContent>>>, templates: Input<Templates>) -> Self {
|
fn new(posts: DynamicInput<Option<Post<HtmlContent>>>, templates: Input<Templates>) -> Self {
|
||||||
@ -274,16 +274,16 @@ impl DynamicRule for MakeWritePosts {
|
|||||||
type ChildOutput = String;
|
type ChildOutput = String;
|
||||||
fn evaluate(&mut self, ctx: &mut impl DynamicRuleContext) -> Vec<Input<Self::ChildOutput>> {
|
fn evaluate(&mut self, ctx: &mut impl DynamicRuleContext) -> Vec<Input<Self::ChildOutput>> {
|
||||||
for post_input in self.posts.value().inputs.iter() {
|
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
|
let permalink = self
|
||||||
.permalink_factory
|
.permalink_factory
|
||||||
.add_node(ctx, post.path.clone(), |ctx| {
|
.add_node(ctx, post_input.node_id(), |ctx| {
|
||||||
ctx.add_rule(PostPermalink(post_input.clone()))
|
ctx.add_rule(PostPermalink(post_input.clone()))
|
||||||
});
|
});
|
||||||
|
|
||||||
let context = self
|
let context =
|
||||||
.build_context_factory
|
self.build_context_factory
|
||||||
.add_node(ctx, post.path.clone(), |ctx| {
|
.add_node(ctx, post_input.node_id(), |ctx| {
|
||||||
ctx.add_rule(BuildTemplateContext::new(
|
ctx.add_rule(BuildTemplateContext::new(
|
||||||
permalink.clone().into(),
|
permalink.clone().into(),
|
||||||
post_input.clone(),
|
post_input.clone(),
|
||||||
@ -303,11 +303,12 @@ impl DynamicRule for MakeWritePosts {
|
|||||||
|
|
||||||
let output_path =
|
let output_path =
|
||||||
self.output_path_factory
|
self.output_path_factory
|
||||||
.add_node(ctx, post.path.clone(), |ctx| {
|
.add_node(ctx, post_input.node_id(), |ctx| {
|
||||||
ctx.add_rule(PostOutputPath(permalink))
|
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 {
|
ctx.add_rule(RenderTemplate {
|
||||||
name: "article",
|
name: "article",
|
||||||
output_path: output_path.into(),
|
output_path: output_path.into(),
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use compute_graph::{
|
use compute_graph::{
|
||||||
|
NodeId,
|
||||||
builder::GraphBuilder,
|
builder::GraphBuilder,
|
||||||
input::{DynamicInput, Input, InputVisitable},
|
input::{DynamicInput, Input, InputVisitable},
|
||||||
rule::{DynamicNodeFactory, DynamicRule, Rule},
|
rule::{DynamicNodeFactory, DynamicRule, Rule},
|
||||||
@ -167,8 +168,8 @@ struct MakeWriteTagPages {
|
|||||||
tags: DynamicInput<TagAndPosts>,
|
tags: DynamicInput<TagAndPosts>,
|
||||||
#[skip_visit]
|
#[skip_visit]
|
||||||
templates: Input<Templates>,
|
templates: Input<Templates>,
|
||||||
build_context_factory: DynamicNodeFactory<String, Context>,
|
build_context_factory: DynamicNodeFactory<NodeId, Context>,
|
||||||
render_factory: DynamicNodeFactory<String, String>,
|
render_factory: DynamicNodeFactory<NodeId, String>,
|
||||||
}
|
}
|
||||||
impl MakeWriteTagPages {
|
impl MakeWriteTagPages {
|
||||||
fn new(tags: DynamicInput<TagAndPosts>, templates: Input<Templates>) -> Self {
|
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() {
|
for tag_input in self.tags.value().inputs.iter() {
|
||||||
let tag_and_posts = tag_input.value();
|
let tag_and_posts = tag_input.value();
|
||||||
let slug = &tag_and_posts.tag.slug;
|
let slug = &tag_and_posts.tag.slug;
|
||||||
let template_context = self
|
let template_context =
|
||||||
.build_context_factory
|
self.build_context_factory
|
||||||
.add_node(ctx, slug.clone(), |ctx| {
|
.add_node(ctx, tag_input.node_id(), |ctx| {
|
||||||
ctx.add_rule(BuildTemplateContext::new(
|
ctx.add_rule(BuildTemplateContext::new(
|
||||||
format!("/{slug}/").into(),
|
format!("/{slug}/").into(),
|
||||||
tag_input.clone(),
|
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 {
|
ctx.add_rule(RenderTemplate {
|
||||||
name: "tag",
|
name: "tag",
|
||||||
output_path: format!("/{slug}/index.html").into(),
|
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::util::{content_path, from_frontmatter};
|
||||||
use super::{FileWatcher, templates::Templates};
|
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(
|
pub fn make_graph(
|
||||||
builder: &mut GraphBuilder<(), Asynchronous>,
|
builder: &mut GraphBuilder<(), Asynchronous>,
|
||||||
default_template: Input<Templates>,
|
default_template: Input<Templates>,
|
||||||
|
@ -7,6 +7,7 @@ use std::{
|
|||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use chrono::{DateTime, Local, NaiveDate};
|
use chrono::{DateTime, Local, NaiveDate};
|
||||||
use compute_graph::{
|
use compute_graph::{
|
||||||
|
NodeId,
|
||||||
builder::GraphBuilder,
|
builder::GraphBuilder,
|
||||||
input::{DynamicInput, Input, InputVisitable},
|
input::{DynamicInput, Input, InputVisitable},
|
||||||
rule::{DynamicNodeFactory, DynamicRule, DynamicRuleContext, Rule},
|
rule::{DynamicNodeFactory, DynamicRule, DynamicRuleContext, Rule},
|
||||||
@ -266,8 +267,8 @@ struct MakeRenderShows {
|
|||||||
shows: DynamicInput<Option<Show>>,
|
shows: DynamicInput<Option<Show>>,
|
||||||
#[skip_visit]
|
#[skip_visit]
|
||||||
templates: Input<Templates>,
|
templates: Input<Templates>,
|
||||||
build_context_factory: DynamicNodeFactory<String, Context>,
|
build_context_factory: DynamicNodeFactory<NodeId, Context>,
|
||||||
render_factory: DynamicNodeFactory<String, String>,
|
render_factory: DynamicNodeFactory<NodeId, String>,
|
||||||
}
|
}
|
||||||
impl MakeRenderShows {
|
impl MakeRenderShows {
|
||||||
fn new(shows: DynamicInput<Option<Show>>, templates: Input<Templates>) -> Self {
|
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>> {
|
fn evaluate(&mut self, ctx: &mut impl DynamicRuleContext) -> Vec<Input<Self::ChildOutput>> {
|
||||||
for show_input in self.shows.value().inputs.iter() {
|
for show_input in self.shows.value().inputs.iter() {
|
||||||
if let Some(show) = show_input.value().as_ref() {
|
if let Some(show) = show_input.value().as_ref() {
|
||||||
let context = self
|
let context =
|
||||||
.build_context_factory
|
self.build_context_factory
|
||||||
.add_node(ctx, show.slug.clone(), |ctx| {
|
.add_node(ctx, show_input.node_id(), |ctx| {
|
||||||
ctx.add_rule(BuildTemplateContext::new(
|
ctx.add_rule(BuildTemplateContext::new(
|
||||||
format!("/tv/{}/", show.slug).into(),
|
format!("/tv/{}/", show.slug).into(),
|
||||||
show_input.clone(),
|
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 {
|
ctx.add_rule(RenderTemplate {
|
||||||
name: "show",
|
name: "show",
|
||||||
output_path: format!("/tv/{}/index.html", show.slug).into(),
|
output_path: format!("/tv/{}/index.html", show.slug).into(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user