Skip to content

Commit

Permalink
dev: break change: use sys.args to control layout
Browse files Browse the repository at this point in the history
  • Loading branch information
Myriad-Dreamin committed Jun 15, 2024
1 parent 630e036 commit 0907417
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 37 deletions.
4 changes: 2 additions & 2 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}"
Expand Down
11 changes: 3 additions & 8 deletions cli/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?;
Expand Down Expand Up @@ -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,
));
}
}
Expand Down
4 changes: 2 additions & 2 deletions contrib/typst/book/lib.typ
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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: <https://github.com/Myriad-Dreamin/shiroa/blob/308e0aacc2578e9a0c424d20332c6711d1df8d1c/contrib/typst/gh-pages.typ>
/// default target is "pdf", typst.ts will set it to "web" when rendering to a
Expand All @@ -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:
Expand All @@ -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)
4 changes: 2 additions & 2 deletions contrib/typst/book/typst.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
14 changes: 7 additions & 7 deletions contrib/typst/gh-ebook.typ
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
}
2 changes: 1 addition & 1 deletion contrib/typst/gh-pages.typ
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
7 changes: 0 additions & 7 deletions contrib/typst/variables/typst.toml

This file was deleted.

2 changes: 1 addition & 1 deletion github-pages/docs/book.typ
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

#import "@preview/book:0.2.5": *
#import "@preview/shiroa:0.1.0": *

#show: book

Expand Down
3 changes: 2 additions & 1 deletion github-pages/docs/cli/init.typ
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion github-pages/docs/format/theme.typ
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion github-pages/docs/guide/get-started.typ
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion github-pages/docs/pdf.typ
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 0907417

Please sign in to comment.