Myriad-Dreamin / shiroa

shiroa is a simple tool for creating modern online books in pure typst.
https://myriad-dreamin.github.io/shiroa/
Apache License 2.0
257 stars 16 forks source link

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

Open duskmoon314 opened 4 months ago

duskmoon314 commented 4 months ago

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 commented 4 months ago

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

duskmoon314 commented 4 months ago

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 commented 4 months ago

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

duskmoon314 commented 4 months ago

Thanks!

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