Skip to content

Commit

Permalink
attaching tutor.js
Browse files Browse the repository at this point in the history
  • Loading branch information
amitu committed Oct 27, 2023
1 parent fcf243c commit b39209d
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 1 deletion.
1 change: 1 addition & 0 deletions fastn-core/src/commands/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,7 @@ async fn route(
("get", "/favicon.ico") => favicon().await,
("get", "/test/") => test().await,
("get", "/-/pwd/") => fastn_core::tutor::pwd().await,
("get", "/-/tutor.js") => fastn_core::tutor::js().await,
("get", "/-/shutdown/") => fastn_core::tutor::shutdown().await,
(_, _) => {
serve(
Expand Down
10 changes: 10 additions & 0 deletions fastn-core/src/tutor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ pub async fn pwd() -> fastn_core::Result<fastn_core::http::Response> {
fastn_core::http::api_ok(std::env::current_dir()?.to_string_lossy())
}

pub async fn js() -> fastn_core::Result<fastn_core::http::Response> {
Ok(actix_web::HttpResponse::Ok().body(include_bytes!("../tutor.js").to_vec()))
}

pub async fn shutdown() -> fastn_core::Result<fastn_core::http::Response> {
if !is_tutor() {
return Ok(fastn_core::not_found!("this only works in tutor mode"));
Expand Down Expand Up @@ -148,7 +152,10 @@ struct Tutorial {
url: String,
title: String,
done: bool,
/// current means this is the tutorial the user is currently working on
current: bool,
/// active means this is the page the user is seeing right now
active: bool,
}

impl Tutorial {
Expand All @@ -165,6 +172,7 @@ impl Tutorial {
current: state.current == id,
url: format!("/{id}/"),
id,
active: false,
})
}
}
Expand Down Expand Up @@ -194,6 +202,7 @@ mod test {
title: "Install and start using `fastn`".to_string(),
done: false,
current: false,
active: false,
}],
},
super::Workshop {
Expand All @@ -207,6 +216,7 @@ mod test {
title: "Install and start using `fastn`".to_string(),
done: false,
current: false,
active: false,
}],
},
],
Expand Down
10 changes: 10 additions & 0 deletions fastn-core/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,16 @@ pub fn replace_markers_2023(
)
.as_str(),
)
.replace(
"__extra_js__",
get_extra_js(
config.ftd_external_js.as_slice(),
config.ftd_inline_js.as_slice(),
"",
"",
)
.as_str(),
)
.replace("__default_css__", default_css)
.replace("__base_url__", base_url)
.as_str(),
Expand Down
19 changes: 19 additions & 0 deletions fastn-core/tutor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
(function() {
document.addEventListener("DOMContentLoaded", function() {
console.log("onload 1");

let iframe = document.createElement('iframe');
// iframe.src = "/-/tutor/";
iframe.src = "https://fastn.com/";
iframe.style.position = "fixed";
iframe.style.top = "0";
iframe.style.left = "0";
iframe.style.width = "100px";
iframe.style.height = "100vh";

document.body.style.paddingLeft = "100px";
document.body.insertBefore(iframe, document.body.firstChild);
console.log("onload");
});
console.log("registered");
})();
2 changes: 1 addition & 1 deletion fastn/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ async fn fastn_core_commands(matches: &clap::ArgMatches) -> fastn_core::Result<(
Some(2000),
None,
Some("2023".to_string()),
vec![],
vec!["/-/tutor.js".to_string()],
vec![],
vec![],
vec![],
Expand Down
2 changes: 2 additions & 0 deletions ftd/ftd-js.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b39209d

Please sign in to comment.