Skip to content

Commit

Permalink
Warnings and delay assets copy
Browse files Browse the repository at this point in the history
  • Loading branch information
snoyberg committed Apr 5, 2024
1 parent 015ad6e commit 675e2dd
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions make-it-static/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl App {
if route.starts_with("/wiki") {
return;
}
if let Some(route) = route.strip_prefix("/") {
if let Some(route) = route.strip_prefix('/') {
if !self.processed.contains(route) {
self.processed.insert(route.to_owned());
self.queue.push_back(route.to_owned());
Expand Down Expand Up @@ -61,9 +61,6 @@ fn main() -> Result<()> {
.args(["-r", "../static", "../public/static"])
.status()?;
anyhow::ensure!(status.success(), "Failed copying static dir");
let status = Command::new("cp")
.args(["-r", "../content/static", "../public/assets"])
.status()?;

let client = reqwest::blocking::Client::new();
let running_server = RunningServer::new(&client)?;
Expand All @@ -83,14 +80,19 @@ fn main() -> Result<()> {
while let Some(route) = app.queue.pop_front() {
process(&mut app, route)?;
}

// Wait until after the server has started to ensure we clone the content repo.
let status = Command::new("cp")
.args(["-r", "../content/static", "../public/assets"])
.status()?;
anyhow::ensure!(status.success(), "Failed copying assets dir");

Ok(())
}

fn process(app: &mut App, route: String) -> Result<()> {
anyhow::ensure!(!route.contains(".."), "No double dots allowed!");
anyhow::ensure!(!route.starts_with("/"), "No leading slashes: {route}");
anyhow::ensure!(!route.starts_with('/'), "No leading slashes: {route}");
let url = format!("{}/{route}", app.running_server.host_root());
let res = app
.client
Expand Down Expand Up @@ -128,7 +130,7 @@ fn process(app: &mut App, route: String) -> Result<()> {
if is_html {
let body =
std::str::from_utf8(&body).with_context(|| format!("Non-UTF8 content in {url}"))?;
handle_html(app, &body)?;
handle_html(app, body)?;
}

Ok(())
Expand Down

0 comments on commit 675e2dd

Please sign in to comment.