From 0907417d4c65d64efa3c6818aeb2d965b013e42f Mon Sep 17 00:00:00 2001 From: Myriad-Dreamin Date: Sat, 15 Jun 2024 10:56:49 +0800 Subject: [PATCH] dev: break change: use sys.args to control layout --- cli/src/main.rs | 4 ++-- cli/src/project.rs | 11 +++-------- contrib/typst/book/lib.typ | 4 ++-- contrib/typst/{variables/lib.typ => book/sys.typ} | 6 +++--- contrib/typst/book/typst.toml | 4 ++-- contrib/typst/gh-ebook.typ | 14 +++++++------- contrib/typst/gh-pages.typ | 2 +- contrib/typst/variables/typst.toml | 7 ------- github-pages/docs/book.typ | 2 +- github-pages/docs/cli/init.typ | 3 ++- github-pages/docs/format/theme.typ | 3 ++- github-pages/docs/guide/get-started.typ | 2 +- github-pages/docs/pdf.typ | 2 +- 13 files changed, 27 insertions(+), 37 deletions(-) rename contrib/typst/{variables/lib.typ => book/sys.typ} (76%) delete mode 100644 contrib/typst/variables/typst.toml diff --git a/cli/src/main.rs b/cli/src/main.rs index bd84f2f..4ecc0a6 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -100,7 +100,7 @@ async fn init(args: InitArgs) -> ZResult<()> { dir.join("book.typ"), format!( r##" -#import "@preview/book:0.2.5": * +#import "@preview/shiroa:0.1.0": * #show: book @@ -135,7 +135,7 @@ Sample page write_file( dir.join("ebook.typ"), format!( - r##"#import "@preview/book:0.2.5": * + r##"#import "@preview/shiroa:0.1.0": * #import "{ebook_template}" diff --git a/cli/src/project.rs b/cli/src/project.rs index 67ef93a..f3e1f78 100644 --- a/cli/src/project.rs +++ b/cli/src/project.rs @@ -121,11 +121,6 @@ impl Project { include_dir!("$CARGO_MANIFEST_DIR/../contrib/typst/book"), ); - release_packages( - proj.tr.compiler.world_mut(), - include_dir!("$CARGO_MANIFEST_DIR/../contrib/typst/variables"), - ); - if matches!(proj.meta_source, MetaSource::Strict) { assert!(entry_file.is_none()); proj.compile_meta()?; @@ -189,12 +184,12 @@ impl Project { let package_meta = res .first() - .ok_or_else(|| error_once!("no internal-package meta in book.typ (are you using old book package?, please import @preview/book:0.2.5; or do you forget the show rule `#show: book`?)"))?; + .ok_or_else(|| error_once!("no internal-package meta in book.typ (are you using old book package?, please import @preview/shiroa:0.1.0; or do you forget the show rule `#show: book`?)"))?; let InternalPackageMeta::Package { version } = &package_meta.value; - if version != "0.2.5" { + if version != "0.1.0" { return Err(error_once!( - "outdated book package, please import @preview/book:0.2.5", importing_version: version, + "outdated book package, please import @preview/shiroa:0.1.0", importing_version: version, )); } } diff --git a/contrib/typst/book/lib.typ b/contrib/typst/book/lib.typ index 00ce61d..0b0c9b4 100644 --- a/contrib/typst/book/lib.typ +++ b/contrib/typst/book/lib.typ @@ -1,7 +1,7 @@ -#import "@preview/typst-ts-variables:0.1.0": page-width, target +#import "sys.typ": target, page-width -// export typst.ts variables again, don't import typst-ts-variables directly +// export typst.ts variables again, don't use sys arguments directly #let get-page-width() = page-width #let target = target #let is-web-target() = target.starts-with("web") diff --git a/contrib/typst/variables/lib.typ b/contrib/typst/book/sys.typ similarity index 76% rename from contrib/typst/variables/lib.typ rename to contrib/typst/book/sys.typ index afd2db0..4a8e715 100644 --- a/contrib/typst/variables/lib.typ +++ b/contrib/typst/book/sys.typ @@ -1,4 +1,4 @@ -//! This is a stub package for typst.ts's dyn-svg controlling the layout +//! Variables for typst.ts's dyn-svg controlling the layout //! Here is a good example of dynamic layout template: /// default target is "pdf", typst.ts will set it to "web" when rendering to a @@ -8,7 +8,7 @@ /// #let is-web-target() = target.starts-with("web") /// #let is-pdf-target() = target.starts-with("pdf") /// ``` -#let target = "pdf" +#let target = sys.inputs.at("x-target", default: "pdf") /// It is in default A4 paper size /// example: @@ -18,4 +18,4 @@ /// height: auto, // Also, for a website, we don't need pagination. /// ) if is-web-target; /// ``` -#let page-width = 595.28pt +#let page-width = sys.inputs.at("x-page-width", default: 595.28pt) diff --git a/contrib/typst/book/typst.toml b/contrib/typst/book/typst.toml index 4047736..ff1efd1 100644 --- a/contrib/typst/book/typst.toml +++ b/contrib/typst/book/typst.toml @@ -1,6 +1,6 @@ [package] -name = "book" -version = "0.2.5" +name = "shiroa" +version = "0.1.0" entrypoint = "lib.typ" authors = ["Myriad-Dreamin"] license = "Apache-2.0" diff --git a/contrib/typst/gh-ebook.typ b/contrib/typst/gh-ebook.typ index 32953da..fcae82c 100644 --- a/contrib/typst/gh-ebook.typ +++ b/contrib/typst/gh-ebook.typ @@ -1,4 +1,4 @@ -#import "@preview/book:0.2.5": * +#import "@preview/shiroa:0.1.0": * #import "/contrib/typst/gh-pages.typ": project, part-style #let _page-project = project @@ -12,25 +12,25 @@ author: authors, title: title, ) - + // inherit from gh-pages show: _page-project - + if title != "" { heading(title) } - + locate(loc => { let inc = _resolve-inclusion-state.final(loc) external-book(spec: inc(spec)) - + let mt = book-meta-state.final(loc) let styles = (inc: inc, part: part-style, chapter: it => it) - + if mt != none { mt.summary.map(it => visit-summary(it, styles)).sum() } }) - + content } \ No newline at end of file diff --git a/contrib/typst/gh-pages.typ b/contrib/typst/gh-pages.typ index 5ff9389..c277924 100644 --- a/contrib/typst/gh-pages.typ +++ b/contrib/typst/gh-pages.typ @@ -1,6 +1,6 @@ // This is important for shiroa to produce a responsive layout // and multiple targets. -#import "@preview/book:0.2.5": get-page-width, target, is-web-target, is-pdf-target, plain-text +#import "@preview/shiroa:0.1.0": get-page-width, target, is-web-target, is-pdf-target, plain-text #let page-width = get-page-width() #let is-pdf-target = is-pdf-target() diff --git a/contrib/typst/variables/typst.toml b/contrib/typst/variables/typst.toml deleted file mode 100644 index 50123d5..0000000 --- a/contrib/typst/variables/typst.toml +++ /dev/null @@ -1,7 +0,0 @@ -[package] -name = "typst-ts-variables" -version = "0.1.0" -entrypoint = "lib.typ" -authors = ["Myriad-Dreamin"] -license = "Apache-2.0" -description = "variable stub for typst.ts." diff --git a/github-pages/docs/book.typ b/github-pages/docs/book.typ index 8dfdfc0..9e31ec1 100644 --- a/github-pages/docs/book.typ +++ b/github-pages/docs/book.typ @@ -1,5 +1,5 @@ -#import "@preview/book:0.2.5": * +#import "@preview/shiroa:0.1.0": * #show: book diff --git a/github-pages/docs/cli/init.typ b/github-pages/docs/cli/init.typ index 5b2ce8c..5802d9f 100644 --- a/github-pages/docs/cli/init.typ +++ b/github-pages/docs/cli/init.typ @@ -32,7 +32,7 @@ shiroa build my-book/ # memoryized dest-dir The harder way, by creating the book without `init` command, your `book.typ` should at least provides a `book-meta`, as #cross-link("/guide/get-started.typ")[Get Started] shown. ```typ -#import "@preview/book:0.2.5": * +#import "@preview/shiroa:0.1.0": * #show: book #book-meta( @@ -43,6 +43,7 @@ The harder way, by creating the book without `init` command, your `book.typ` sho ) ``` +// todo: update it What is arguable, your `template.typ` must import and respect the `page-width` and `target` variable from `@preview/typst-ts-variables:0.1.0` to this time. ```typ diff --git a/github-pages/docs/format/theme.typ b/github-pages/docs/format/theme.typ index 9180235..824a38f 100644 --- a/github-pages/docs/format/theme.typ +++ b/github-pages/docs/format/theme.typ @@ -17,7 +17,7 @@ Currently we have no much design on theme's html part. But you can still configu Your `book.typ` should at least provides a `book-meta`, as #t shown. ```typ -#import "@preview/book:0.2.5": * +#import "@preview/shiroa:0.1.0": * #show: book #book-meta( @@ -28,6 +28,7 @@ Your `book.typ` should at least provides a `book-meta`, as #t shown. ) ``` +// todo: update it What is arguable, your `template.typ` must import and respect the `page-width` and `target` variable from `@preview/typst-ts-variables:0.1.0` to this time. ```typ diff --git a/github-pages/docs/guide/get-started.typ b/github-pages/docs/guide/get-started.typ index 804987b..c4e6373 100644 --- a/github-pages/docs/guide/get-started.typ +++ b/github-pages/docs/guide/get-started.typ @@ -48,7 +48,7 @@ Before a chapter can be viewed, it must be added to this list. Here's a basic summary file with a few chapters: ```typ -#import "@preview/book:0.2.5": * +#import "@preview/shiroa:0.1.0": * #show: book #book-meta( // put metadata of your book like book.toml of mdbook diff --git a/github-pages/docs/pdf.typ b/github-pages/docs/pdf.typ index 758cd14..6b52fd0 100644 --- a/github-pages/docs/pdf.typ +++ b/github-pages/docs/pdf.typ @@ -1,4 +1,4 @@ -#import "@preview/book:0.2.5": * +#import "@preview/shiroa:0.1.0": * #import "/contrib/typst/gh-ebook.typ" #let ebook = gh-ebook