summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.rs18
-rw-r--r--src/works/mod.rs8
-rw-r--r--src/works/stories.rs6
3 files changed, 16 insertions, 16 deletions
diff --git a/src/main.rs b/src/main.rs
index 4dc6e5e..a531785 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,7 +1,8 @@
use anyhow::{Context, Ok, Result};
use tera::Tera;
-use crate::works::Works;
+use self::works::stories::Stories;
+use self::works::Works;
mod works;
@@ -17,15 +18,14 @@ fn main() -> Result<()> {
std::fs::write("docs/index.html", output).context("Failed to write index.html")?;
// render stories.html file
- let stories = std::rc::Rc::new(works::stories::Stories::new_from_file(
+ Stories::new_from_file(
&std::fs::File::open(std::path::PathBuf::from("stories.json"))
.context("Failed to open stories.json")?,
- )?);
- std::rc::Rc::clone(&stories)
- .render_overview_page(&tera, "stories")
- .context("Failed to render overview page for stories")?;
- std::rc::Rc::clone(&stories)
- .render_single_pages(&tera, "story")
- .context("Failed to render single pages for stories")?;
+ )?
+ .render_overview_page(&tera, "stories")
+ .context("Failed to render overview page for stories")?
+ .render_single_pages(&tera, "story")
+ .context("Failed to render single pages for stories")?;
+
Ok(())
}
diff --git a/src/works/mod.rs b/src/works/mod.rs
index 77dd35d..0970cb1 100644
--- a/src/works/mod.rs
+++ b/src/works/mod.rs
@@ -22,15 +22,15 @@ pub trait Works: for<'a> Deserialize<'a> + Serialize {
}
// render page for every work
- fn render_single_pages(&self, tera_instance: &tera::Tera, template_name: &str) -> Result<()>;
+ fn render_single_pages(self, tera_instance: &tera::Tera, template_name: &str) -> Result<Self>;
// render corresponding overview HTML template
// with its tera context
fn render_overview_page(
- &self,
+ self,
tera_instance: &tera::Tera,
filename_without_extension: &str,
- ) -> Result<()> {
+ ) -> Result<Self> {
std::fs::write(
format!("docs/{}.html", filename_without_extension).as_str(),
tera_instance
@@ -51,6 +51,6 @@ pub trait Works: for<'a> Deserialize<'a> + Serialize {
filename_without_extension
)
})?;
- Ok(())
+ Ok(self)
}
}
diff --git a/src/works/stories.rs b/src/works/stories.rs
index f86d24a..2623db6 100644
--- a/src/works/stories.rs
+++ b/src/works/stories.rs
@@ -24,10 +24,10 @@ struct Story {
impl super::Works for Stories {
// render single pages for every story with the extracted text and a download button
fn render_single_pages(
- &self,
+ self,
tera_instance: &tera::Tera,
template_name: &str,
- ) -> Result<()> {
+ ) -> Result<Self> {
let mut result = Vec::new();
for story in self.0.iter() {
if story.update_available().with_context(|| format!("Failed to check for update for {}", story.title))? {
@@ -40,7 +40,7 @@ impl super::Works for Stories {
));
}
}
- Ok(())
+ Ok(self)
}
// create stories from stories.json and add last modification date