Skip to content

Commit f61e81f

Browse files
committed
Do blog generation as part of the invocation of the embedded web server.
(I'm not yet trying to do any fancy monitoring of changes to the files and subsequent regeneration. This is all meant to be very bare bones.) To accomplish this I had to make the main crate callable from other crates, which in turn required some small changes to how it pulls in its own child modules, since `main` can no longer assume it is the crate root.
1 parent e273b2e commit f61e81f

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

src/bin/serve.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
use std::error::Error;
22

3+
#[path="../main.rs"] mod main;
4+
35
#[tokio::main]
46
async fn main() -> Result<(), Box<dyn Error>> {
7+
main::main()?;
8+
59
let footer = format!("{} {}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"));
610

711
warpy::server::run(format!("{}/site", env!("CARGO_MANIFEST_DIR")), [0, 0, 0, 0], footer, Some(8000), false).await?;

src/blogs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::posts::Post;
1+
use super::posts::Post;
22
use serde_derive::{Deserialize, Serialize};
33
use std::error::Error;
44
use std::path::{Path, PathBuf};

src/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
mod blogs;
22
mod posts;
33

4-
use crate::blogs::Blog;
5-
use crate::posts::Post;
4+
use self::blogs::Blog;
5+
use self::posts::Post;
66
use chrono::Timelike;
77
use handlebars::{handlebars_helper, Handlebars};
88
use sass_rs::{compile_file, Options};
@@ -59,7 +59,7 @@ impl<'a> Generator<'a> {
5959

6060
Ok(Generator {
6161
handlebars,
62-
blogs: crate::blogs::load(posts_directory.as_ref())?,
62+
blogs: self::blogs::load(posts_directory.as_ref())?,
6363
out_directory: out_directory.as_ref().into(),
6464
})
6565
}
@@ -251,7 +251,7 @@ impl<'a> Generator<'a> {
251251
}
252252
}
253253

254-
fn main() -> Result<(), Box<dyn Error>> {
254+
pub fn main() -> Result<(), Box<dyn Error>> {
255255
let blog = Generator::new("site", "posts")?;
256256

257257
blog.render()?;

src/posts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::blogs::Manifest;
1+
use super::blogs::Manifest;
22
use comrak::{ComrakExtensionOptions, ComrakOptions, ComrakRenderOptions};
33
use regex::Regex;
44
use serde_derive::{Deserialize, Serialize};

0 commit comments

Comments
 (0)