mirror of
https://github.com/typst/typst
synced 2025-05-22 13:05:29 +08:00
Add ability to set document keywords. (#2234)
This commit is contained in:
parent
34b3f72370
commit
e33017042d
@ -27,6 +27,9 @@ pub struct DocumentElem {
|
|||||||
/// The document's authors.
|
/// The document's authors.
|
||||||
pub author: Author,
|
pub author: Author,
|
||||||
|
|
||||||
|
/// The document's keywords.
|
||||||
|
pub keywords: Keywords,
|
||||||
|
|
||||||
/// The page runs.
|
/// The page runs.
|
||||||
#[internal]
|
#[internal]
|
||||||
#[variadic]
|
#[variadic]
|
||||||
@ -77,6 +80,7 @@ impl LayoutRoot for DocumentElem {
|
|||||||
pages,
|
pages,
|
||||||
title: self.title(styles),
|
title: self.title(styles),
|
||||||
author: self.author(styles).0,
|
author: self.author(styles).0,
|
||||||
|
keywords: self.keywords(styles).0,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -91,3 +95,14 @@ cast! {
|
|||||||
v: EcoString => Self(vec![v]),
|
v: EcoString => Self(vec![v]),
|
||||||
v: Array => Self(v.into_iter().map(Value::cast).collect::<StrResult<_>>()?),
|
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<_>>()?),
|
||||||
|
}
|
||||||
|
@ -28,6 +28,8 @@ pub struct Document {
|
|||||||
pub title: Option<EcoString>,
|
pub title: Option<EcoString>,
|
||||||
/// The document's author.
|
/// The document's author.
|
||||||
pub author: Vec<EcoString>,
|
pub author: Vec<EcoString>,
|
||||||
|
/// The document's keywords.
|
||||||
|
pub keywords: Vec<EcoString>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A finished layout with items at fixed positions.
|
/// A finished layout with items at fixed positions.
|
||||||
|
@ -132,6 +132,14 @@ fn write_catalog(ctx: &mut PdfContext) {
|
|||||||
info.author(TextStr(&authors.join(", ")));
|
info.author(TextStr(&authors.join(", ")));
|
||||||
xmp.creator(authors.iter().map(|s| s.as_str()));
|
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.creator(TextStr("Typst"));
|
||||||
info.finish();
|
info.finish();
|
||||||
xmp.creator_tool("Typst");
|
xmp.creator_tool("Typst");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user