From b39209d404f9c34dde81ef892e5ea96d3467b9f0 Mon Sep 17 00:00:00 2001 From: Amit Upadhyay Date: Fri, 27 Oct 2023 21:57:32 +0530 Subject: [PATCH 01/32] attaching tutor.js --- fastn-core/src/commands/serve.rs | 1 + fastn-core/src/tutor.rs | 10 ++++++++++ fastn-core/src/utils.rs | 10 ++++++++++ fastn-core/tutor.js | 19 +++++++++++++++++++ fastn/src/main.rs | 2 +- ftd/ftd-js.html | 2 ++ 6 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 fastn-core/tutor.js diff --git a/fastn-core/src/commands/serve.rs b/fastn-core/src/commands/serve.rs index 0bbf40fc35..5b1f966f29 100644 --- a/fastn-core/src/commands/serve.rs +++ b/fastn-core/src/commands/serve.rs @@ -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( diff --git a/fastn-core/src/tutor.rs b/fastn-core/src/tutor.rs index 65c3229a01..7fffe1ab06 100644 --- a/fastn-core/src/tutor.rs +++ b/fastn-core/src/tutor.rs @@ -6,6 +6,10 @@ pub async fn pwd() -> fastn_core::Result { fastn_core::http::api_ok(std::env::current_dir()?.to_string_lossy()) } +pub async fn js() -> fastn_core::Result { + Ok(actix_web::HttpResponse::Ok().body(include_bytes!("../tutor.js").to_vec())) +} + pub async fn shutdown() -> fastn_core::Result { if !is_tutor() { return Ok(fastn_core::not_found!("this only works in tutor mode")); @@ -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 { @@ -165,6 +172,7 @@ impl Tutorial { current: state.current == id, url: format!("/{id}/"), id, + active: false, }) } } @@ -194,6 +202,7 @@ mod test { title: "Install and start using `fastn`".to_string(), done: false, current: false, + active: false, }], }, super::Workshop { @@ -207,6 +216,7 @@ mod test { title: "Install and start using `fastn`".to_string(), done: false, current: false, + active: false, }], }, ], diff --git a/fastn-core/src/utils.rs b/fastn-core/src/utils.rs index 2a237d35dc..e47792bb17 100644 --- a/fastn-core/src/utils.rs +++ b/fastn-core/src/utils.rs @@ -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(), diff --git a/fastn-core/tutor.js b/fastn-core/tutor.js new file mode 100644 index 0000000000..e6134faecb --- /dev/null +++ b/fastn-core/tutor.js @@ -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"); +})(); \ No newline at end of file diff --git a/fastn/src/main.rs b/fastn/src/main.rs index ffc73481d8..32eabbda00 100644 --- a/fastn/src/main.rs +++ b/fastn/src/main.rs @@ -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![], diff --git a/ftd/ftd-js.html b/ftd/ftd-js.html index 8113699d14..62934ad4c0 100644 --- a/ftd/ftd-js.html +++ b/ftd/ftd-js.html @@ -1,3 +1,4 @@ + @@ -10,6 +11,7 @@ __script_file__ + __extra_js__