From 497446944c78bcf598e8ac8dcdff6c0d0433d844 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Mon, 2 Dec 2024 13:48:45 +0100 Subject: [PATCH] Add `document.description` field --- crates/typst-library/src/model/document.rs | 10 ++++++++++ crates/typst-pdf/src/catalog.rs | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/crates/typst-library/src/model/document.rs b/crates/typst-library/src/model/document.rs index c333dff33..5124b2487 100644 --- a/crates/typst-library/src/model/document.rs +++ b/crates/typst-library/src/model/document.rs @@ -37,6 +37,10 @@ pub struct DocumentElem { #[ghost] pub author: Author, + /// The document's description. + #[ghost] + pub description: Option, + /// The document's keywords. #[ghost] pub keywords: Keywords, @@ -91,6 +95,8 @@ pub struct DocumentInfo { pub title: Option, /// The document's author. pub author: Vec, + /// The document's description. + pub description: Option, /// The document's keywords. pub keywords: Vec, /// The document's creation date. @@ -111,6 +117,10 @@ impl DocumentInfo { if has(::Enum::Author) { self.author = DocumentElem::author_in(chain).0; } + if has(::Enum::Description) { + self.description = + DocumentElem::description_in(chain).map(|content| content.plain_text()); + } if has(::Enum::Keywords) { self.keywords = DocumentElem::keywords_in(chain).0; } diff --git a/crates/typst-pdf/src/catalog.rs b/crates/typst-pdf/src/catalog.rs index 35c5ce681..753b8cb6b 100644 --- a/crates/typst-pdf/src/catalog.rs +++ b/crates/typst-pdf/src/catalog.rs @@ -48,6 +48,11 @@ pub fn write_catalog( xmp.title([(None, title.as_str())]); } + if let Some(description) = &ctx.document.info.description { + info.subject(TextStr::trimmed(description)); + xmp.description([(None, description.as_str())]); + } + let authors = &ctx.document.info.author; if !authors.is_empty() { // Turns out that if the authors are given in both the document