From 7f7d69f9b7cf4f341baefbac85ca003a1466010c Mon Sep 17 00:00:00 2001 From: Arpita-Jaiswal Date: Fri, 10 Mar 2023 14:04:13 +0530 Subject: [PATCH] added ftd files in .build folder --- fastn-core/src/commands/build.rs | 30 +- fastn-core/src/commands/serve.rs | 3 + fastn-core/src/package/mod.rs | 4 +- fastn-core/src/utils.rs | 4 + fastn-core/tests/02-hello/output/fail_doc.ftd | 3 + fastn-core/tests/02-hello/output/index.ftd | 34 + .../tests/03-nested-document/output/index.ftd | 1 + .../output/nested/document.ftd | 1 + .../output/nested/index.ftd | 1 + .../04-import-code-block/output/index.ftd | 11 + .../tests/04-import-code-block/output/lib.ftd | 10 + fastn-core/tests/05-hello-font/cmd.p1 | 1 + .../output/-/www.amitu.com/index-dark.jpg | 903 ++++++++++++++++++ .../tests/05-hello-font/output/index.ftd | 49 + .../tests/05-hello-font/output/index.html | 6 +- .../tests/08-static-assets/output/index.ftd | 1 + .../tests/09-markdown-pages/output/index.ftd | 1 + .../11-readme-with-index/output/index.ftd | 1 + .../15-fpm-dependency-alias/output/index.ftd | 5 + .../16-include-processor/output/index.ftd | 7 + 20 files changed, 1057 insertions(+), 19 deletions(-) create mode 100644 fastn-core/tests/02-hello/output/fail_doc.ftd create mode 100644 fastn-core/tests/02-hello/output/index.ftd create mode 100644 fastn-core/tests/03-nested-document/output/index.ftd create mode 100644 fastn-core/tests/03-nested-document/output/nested/document.ftd create mode 100644 fastn-core/tests/03-nested-document/output/nested/index.ftd create mode 100644 fastn-core/tests/04-import-code-block/output/index.ftd create mode 100644 fastn-core/tests/04-import-code-block/output/lib.ftd create mode 100644 fastn-core/tests/05-hello-font/output/-/www.amitu.com/index-dark.jpg create mode 100644 fastn-core/tests/05-hello-font/output/index.ftd create mode 100644 fastn-core/tests/08-static-assets/output/index.ftd create mode 100644 fastn-core/tests/09-markdown-pages/output/index.ftd create mode 100644 fastn-core/tests/11-readme-with-index/output/index.ftd create mode 100644 fastn-core/tests/15-fpm-dependency-alias/output/index.ftd create mode 100644 fastn-core/tests/16-include-processor/output/index.ftd diff --git a/fastn-core/src/commands/build.rs b/fastn-core/src/commands/build.rs index a2fa53a07a..c9cc24cfc6 100644 --- a/fastn-core/src/commands/build.rs +++ b/fastn-core/src/commands/build.rs @@ -31,24 +31,26 @@ pub async fn build( if !config .ftd_edition .eq(&fastn_core::config::FTDEdition::FTD2021) - && doc.id.eq("FASTN.ftd") { - tokio::fs::copy( + fastn_core::utils::copy( config.root.join(doc.id.as_str()), config.root.join(".build").join(doc.id.as_str()), ) - .await?; - - fastn_core::utils::print_end( - format!( - "Processed {}/{}", - config.package.name.as_str(), - main.get_id() - ) - .as_str(), - start, - ); - continue; + .await + .ok(); + + if doc.id.eq("FASTN.ftd") { + fastn_core::utils::print_end( + format!( + "Processed {}/{}", + config.package.name.as_str(), + main.get_id() + ) + .as_str(), + start, + ); + continue; + } } let resp = fastn_core::package::package_doc::process_ftd( config, doc, base_url, no_static, test, diff --git a/fastn-core/src/commands/serve.rs b/fastn-core/src/commands/serve.rs index 68eb0a1683..fda1c85fa7 100644 --- a/fastn-core/src/commands/serve.rs +++ b/fastn-core/src/commands/serve.rs @@ -70,6 +70,9 @@ async fn serve_file( match f { fastn_core::File::Ftd(main_document) => { + if fastn_core::utils::is_ftd_path(path.as_str()) { + return fastn_core::http::ok(main_document.content.as_bytes().to_vec()); + } match fastn_core::package::package_doc::read_ftd( config, &main_document, diff --git a/fastn-core/src/package/mod.rs b/fastn-core/src/package/mod.rs index 74649129db..255e94589f 100644 --- a/fastn-core/src/package/mod.rs +++ b/fastn-core/src/package/mod.rs @@ -719,14 +719,14 @@ impl PackageTemp { .collect::>(); Package { - name: self.name, + name: self.name.clone(), versioned: self.versioned, translation_of: Box::new(translation_of), translations, language: self.language, about: self.about, zip: self.zip, - download_base_url: self.download_base_url, + download_base_url: self.download_base_url.or(Some(self.name)), translation_status_summary: None, canonical_url: self.canonical_url, dependencies: vec![], diff --git a/fastn-core/src/utils.rs b/fastn-core/src/utils.rs index 6c8afc9812..62f5462b98 100644 --- a/fastn-core/src/utils.rs +++ b/fastn-core/src/utils.rs @@ -778,3 +778,7 @@ mod tests { pub fn ignore_headers() -> Vec<&'static str> { vec!["host", "x-forwarded-ssl"] } + +pub(crate) fn is_ftd_path(path: &str) -> bool { + path.trim_matches('/').ends_with(".ftd") +} diff --git a/fastn-core/tests/02-hello/output/fail_doc.ftd b/fastn-core/tests/02-hello/output/fail_doc.ftd new file mode 100644 index 0000000000..367858c453 --- /dev/null +++ b/fastn-core/tests/02-hello/output/fail_doc.ftd @@ -0,0 +1,3 @@ +-- import: xyz + +-- xyz.dummy_component: Caption \ No newline at end of file diff --git a/fastn-core/tests/02-hello/output/index.ftd b/fastn-core/tests/02-hello/output/index.ftd new file mode 100644 index 0000000000..1e053848fc --- /dev/null +++ b/fastn-core/tests/02-hello/output/index.ftd @@ -0,0 +1,34 @@ +-- ftd.text: hello + +-- ftd.text: Hello World +region: h2 +role: $rtype + + +-- ftd.text: hello_h1 +region: h1 +role: $inherited.types.copy-regular +color: $inherited.colors.text + +-- ftd.text: hello_h0 +region: h3 +role: $dtype + + +-- ftd.type dtype: +size.px: 40 +weight: 700 +font-family: cursive +line-height.px: 65 +letter-spacing.px: 5 + +-- ftd.type mtype: +size.px: 20 +weight: 100 +font-family: fantasy +line-height.px: 35 +letter-spacing.px: 3 + +-- ftd.responsive-type rtype: +desktop: $dtype +mobile: $mtype diff --git a/fastn-core/tests/03-nested-document/output/index.ftd b/fastn-core/tests/03-nested-document/output/index.ftd new file mode 100644 index 0000000000..5de3d8278d --- /dev/null +++ b/fastn-core/tests/03-nested-document/output/index.ftd @@ -0,0 +1 @@ +-- ftd.text: hello \ No newline at end of file diff --git a/fastn-core/tests/03-nested-document/output/nested/document.ftd b/fastn-core/tests/03-nested-document/output/nested/document.ftd new file mode 100644 index 0000000000..106dd51909 --- /dev/null +++ b/fastn-core/tests/03-nested-document/output/nested/document.ftd @@ -0,0 +1 @@ +-- ftd.text: nested document \ No newline at end of file diff --git a/fastn-core/tests/03-nested-document/output/nested/index.ftd b/fastn-core/tests/03-nested-document/output/nested/index.ftd new file mode 100644 index 0000000000..f0505cd6da --- /dev/null +++ b/fastn-core/tests/03-nested-document/output/nested/index.ftd @@ -0,0 +1 @@ +-- ftd.text: This should be rendered inside amitu/nested/index/index.html \ No newline at end of file diff --git a/fastn-core/tests/04-import-code-block/output/index.ftd b/fastn-core/tests/04-import-code-block/output/index.ftd new file mode 100644 index 0000000000..1333b02a94 --- /dev/null +++ b/fastn-core/tests/04-import-code-block/output/index.ftd @@ -0,0 +1,11 @@ +-- import: amitu/lib +-- import: fifthtry.github.io/package-doc/typography as pd + +-- lib.block: + +-- pd.h1: Heading 1 + +Heading 1 content + + +-- end: lib.block diff --git a/fastn-core/tests/04-import-code-block/output/lib.ftd b/fastn-core/tests/04-import-code-block/output/lib.ftd new file mode 100644 index 0000000000..ff90f1093f --- /dev/null +++ b/fastn-core/tests/04-import-code-block/output/lib.ftd @@ -0,0 +1,10 @@ +-- component block: +children wrapper: + +-- ftd.row: +background.solid: #000000 +children: $block.wrapper + +-- end: ftd.row + +-- end: block diff --git a/fastn-core/tests/05-hello-font/cmd.p1 b/fastn-core/tests/05-hello-font/cmd.p1 index 8443e44cf5..56bb01c17d 100644 --- a/fastn-core/tests/05-hello-font/cmd.p1 +++ b/fastn-core/tests/05-hello-font/cmd.p1 @@ -9,6 +9,7 @@ Processing www.amitu.com/hello.py ... done in Processing www.amitu.com/hello/world/test.py ... done in Processing www.amitu.com/index ... done in Processing www.amitu.com/index.ftd ... Processing www.amitu.com/index.jpg ... done in +Processing www.amitu.com/index-dark.jpg ... done in Processing www.amitu.com/index.ftd ... done in Processing www.amitu.com/hello/world/test.py ... done in Processing www.amitu.com/hello.py ... done in diff --git a/fastn-core/tests/05-hello-font/output/-/www.amitu.com/index-dark.jpg b/fastn-core/tests/05-hello-font/output/-/www.amitu.com/index-dark.jpg new file mode 100644 index 0000000000..dddefe1fb1 --- /dev/null +++ b/fastn-core/tests/05-hello-font/output/-/www.amitu.com/index-dark.jpg @@ -0,0 +1,903 @@ + + + + + + Form Error: {"id": "user not logged in"} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + diff --git a/fastn-core/tests/05-hello-font/output/index.ftd b/fastn-core/tests/05-hello-font/output/index.ftd new file mode 100644 index 0000000000..c728db0c74 --- /dev/null +++ b/fastn-core/tests/05-hello-font/output/index.ftd @@ -0,0 +1,49 @@ +-- import: www.amitu.com/assets + +-- ftd.type roboto: +font-family: $assets.fonts.Roboto +size.px: 10 +weight: 100 +line-height.px: 10 +letter-spacing.px: 5 + +-- ftd.type myFirstFont: +font: $assets.fonts.myFirstFont +size.px: 10 +weight: 100 +line-height.px: 10 +letter-spacing.px: 5 + +-- ftd.text: hello +role: $roboto + +-- ftd.text: hello +role: $myFirstFont + +-- ftd.image: +src: $assets.files.index.jpg + +-- ftd.text: +text: $assets.files.index.jpg.dark + + +-- ftd.text: +text: $assets.files.index.jpg.light + +-- ftd.text: +text: $assets.files.index.ftd + +-- ftd.text: +text: $assets.files.hello.world.test.py + +-- ftd.text: +text: $assets.files.hello.world.test.py + +-- ftd.text: +text: $assets.files.hello.py + +-- ftd.text: +text: $assets.files.hello.py + +-- ftd.text: +text: $assets.files.index diff --git a/fastn-core/tests/05-hello-font/output/index.html b/fastn-core/tests/05-hello-font/output/index.html index bdd47c5383..a15a5678ca 100644 --- a/fastn-core/tests/05-hello-font/output/index.html +++ b/fastn-core/tests/05-hello-font/output/index.html @@ -539,10 +539,10 @@ "www.amitu.com/assets#files.index": "-/www.amitu.com/index", "www.amitu.com/assets#files.index.ftd": "-/www.amitu.com/index.ftd", "www.amitu.com/assets#files.index.jpg": { -"dark": "-/www.amitu.com/index.jpg", +"dark": "-/www.amitu.com/index-dark.jpg", "light": "-/www.amitu.com/index.jpg" }, -"www.amitu.com/assets#files.index.jpg.dark": "-/www.amitu.com/index.jpg", +"www.amitu.com/assets#files.index.jpg.dark": "-/www.amitu.com/index-dark.jpg", "www.amitu.com/assets#files.index.jpg.light": "-/www.amitu.com/index.jpg", "www.amitu.com/assets#fonts": { "Roboto": "www-amitu-com-Roboto", @@ -726,7 +726,7 @@ -

hello

hello

-/www.amitu.com/index.jpg

-/www.amitu.com/index.jpg

-/www.amitu.com/index.ftd

-/www.amitu.com/hello/world/test.py

-/www.amitu.com/hello/world/test.py

-/www.amitu.com/hello.py

-/www.amitu.com/hello.py

-/www.amitu.com/index