Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

book-meta.authors cannot accept sequence with single string #66

Open
duskmoon314 opened this issue Jun 2, 2024 · 4 comments
Open

book-meta.authors cannot accept sequence with single string #66

duskmoon314 opened this issue Jun 2, 2024 · 4 comments

Comments

@duskmoon314
Copy link
Contributor

When I pass a sequence with only one string to book-meta.authors, an error occurs.

#book-meta(
  title: "xxx",
  description: "xxx",
  authors: ("duskmoon"),
  summary: [
    // #prefix-chapter("sample-page.typ")[Hello, typst]
  ],
)

The error:

$ typst-book serve
package book/0.2.5 already exists
package typst-ts-variables/0.1.0 already exists
error: typst-book error: convert_to<BookMeta>: invalid type: string "duskmoon", expected a sequence with []

typst-book version: v0.1.4

@duskmoon314
Copy link
Contributor Author

A workaround seems to add an empty string to the sequence: ("xxx", "")

@duskmoon314
Copy link
Contributor Author

duskmoon314 commented Jun 2, 2024

Very brief research shows that this query's output gives only authors: "duskmoon" instead of sequence. Then the error occurs at serde_json::from_value


Update: This is a typst query feature (I assume this is intended).

For metadata like this:

#metadata((
  authors: ("foo")
)) <meta>

#context {
  query(<meta>).first().value
}

The value we get is (authors: "foo") instead of (authors: ("foo")).

But if we have more than one string:

#metadata((
  authors: ("foo", "bar")
)) <meta>

#context {
  query(<meta>).first().value
}

We get (authors: ("foo", "bar"))


We might need to use enum Author{ Single(String), Multiple(Vec<String>) } to support only one author. Though, I haven't tried this myself.

@Myriad-Dreamin
Copy link
Owner

It could be improved and you can try ("duskmoon",), the array containing single element, as well.

@duskmoon314
Copy link
Contributor Author

Thanks!

I want to keep this issue open for future improvement, though it is not urgent, and we may leave it as it is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants