diff options
| author | Approximately Equal <approximately.equals.zero@gmail.com> | 2025-04-07 13:18:52 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-07 20:18:52 +0000 |
| commit | 94a497a01ffd60743b0a2ae67367be168bbde076 (patch) | |
| tree | ee989e6da182d09c74f61f58103d2ee375aa1342 /crates/typst-html/src | |
| parent | 9829bd8326fc67ebf78593bf4e860390c5ae8804 (diff) | |
Add HTML meta tags for document authors and keywords (#6134)
Diffstat (limited to 'crates/typst-html/src')
| -rw-r--r-- | crates/typst-html/src/lib.rs | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/crates/typst-html/src/lib.rs b/crates/typst-html/src/lib.rs index aa769976..7d78a5da 100644 --- a/crates/typst-html/src/lib.rs +++ b/crates/typst-html/src/lib.rs @@ -263,13 +263,13 @@ fn handle( /// Wrap the nodes in `<html>` and `<body>` if they are not yet rooted, /// supplying a suitable `<head>`. fn root_element(output: Vec<HtmlNode>, info: &DocumentInfo) -> SourceResult<HtmlElement> { + let head = head_element(info); let body = match classify_output(output)? { OutputKind::Html(element) => return Ok(element), OutputKind::Body(body) => body, OutputKind::Leafs(leafs) => HtmlElement::new(tag::body).with_children(leafs), }; - Ok(HtmlElement::new(tag::html) - .with_children(vec![head_element(info).into(), body.into()])) + Ok(HtmlElement::new(tag::html).with_children(vec![head.into(), body.into()])) } /// Generate a `<head>` element. @@ -302,6 +302,24 @@ fn head_element(info: &DocumentInfo) -> HtmlElement { ); } + if !info.author.is_empty() { + children.push( + HtmlElement::new(tag::meta) + .with_attr(attr::name, "authors") + .with_attr(attr::content, info.author.join(", ")) + .into(), + ) + } + + if !info.keywords.is_empty() { + children.push( + HtmlElement::new(tag::meta) + .with_attr(attr::name, "keywords") + .with_attr(attr::content, info.keywords.join(", ")) + .into(), + ) + } + HtmlElement::new(tag::head).with_children(children) } |
