summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorqj <60492138+qrnch-jan@users.noreply.github.com>2023-09-26 10:35:18 +0200
committerGitHub <noreply@github.com>2023-09-26 10:35:18 +0200
commite33017042da6b0a202894fd401e0b99fdc8494e5 (patch)
tree165afbc9c0b5c419a9240f4c7c7576c2910d08ab
parent34b3f7237017ec9b4e463ad2a6d58d469258e66d (diff)
Add ability to set document keywords. (#2234)
-rw-r--r--crates/typst-library/src/meta/document.rs15
-rw-r--r--crates/typst/src/doc.rs2
-rw-r--r--crates/typst/src/export/pdf/mod.rs8
3 files changed, 25 insertions, 0 deletions
diff --git a/crates/typst-library/src/meta/document.rs b/crates/typst-library/src/meta/document.rs
index 200b5d9d..f81d8f8a 100644
--- a/crates/typst-library/src/meta/document.rs
+++ b/crates/typst-library/src/meta/document.rs
@@ -27,6 +27,9 @@ pub struct DocumentElem {
/// The document's authors.
pub author: Author,
+ /// The document's keywords.
+ pub keywords: Keywords,
+
/// The page runs.
#[internal]
#[variadic]
@@ -77,6 +80,7 @@ impl LayoutRoot for DocumentElem {
pages,
title: self.title(styles),
author: self.author(styles).0,
+ keywords: self.keywords(styles).0,
})
}
}
@@ -91,3 +95,14 @@ cast! {
v: EcoString => Self(vec![v]),
v: Array => Self(v.into_iter().map(Value::cast).collect::<StrResult<_>>()?),
}
+
+/// A list of keywords.
+#[derive(Debug, Default, Clone, Hash)]
+pub struct Keywords(Vec<EcoString>);
+
+cast! {
+ Keywords,
+ self => self.0.into_value(),
+ v: EcoString => Self(vec![v]),
+ v: Array => Self(v.into_iter().map(Value::cast).collect::<StrResult<_>>()?),
+}
diff --git a/crates/typst/src/doc.rs b/crates/typst/src/doc.rs
index e3913c1c..91f9ec20 100644
--- a/crates/typst/src/doc.rs
+++ b/crates/typst/src/doc.rs
@@ -28,6 +28,8 @@ pub struct Document {
pub title: Option<EcoString>,
/// The document's author.
pub author: Vec<EcoString>,
+ /// The document's keywords.
+ pub keywords: Vec<EcoString>,
}
/// A finished layout with items at fixed positions.
diff --git a/crates/typst/src/export/pdf/mod.rs b/crates/typst/src/export/pdf/mod.rs
index 6a5aacf5..4043c928 100644
--- a/crates/typst/src/export/pdf/mod.rs
+++ b/crates/typst/src/export/pdf/mod.rs
@@ -132,6 +132,14 @@ fn write_catalog(ctx: &mut PdfContext) {
info.author(TextStr(&authors.join(", ")));
xmp.creator(authors.iter().map(|s| s.as_str()));
}
+
+ let keywords = &ctx.document.keywords;
+ if !keywords.is_empty() {
+ let joined = keywords.join(", ");
+ info.keywords(TextStr(&joined));
+ xmp.pdf_keywords(&joined);
+ }
+
info.creator(TextStr("Typst"));
info.finish();
xmp.creator_tool("Typst");