mirror of
https://github.com/typst/typst
synced 2025-05-13 12:36:23 +08:00
Add HTML meta tags for document authors and keywords (#6134)
This commit is contained in:
parent
9829bd8326
commit
94a497a01f
@ -263,13 +263,13 @@ fn handle(
|
|||||||
/// Wrap the nodes in `<html>` and `<body>` if they are not yet rooted,
|
/// Wrap the nodes in `<html>` and `<body>` if they are not yet rooted,
|
||||||
/// supplying a suitable `<head>`.
|
/// supplying a suitable `<head>`.
|
||||||
fn root_element(output: Vec<HtmlNode>, info: &DocumentInfo) -> SourceResult<HtmlElement> {
|
fn root_element(output: Vec<HtmlNode>, info: &DocumentInfo) -> SourceResult<HtmlElement> {
|
||||||
|
let head = head_element(info);
|
||||||
let body = match classify_output(output)? {
|
let body = match classify_output(output)? {
|
||||||
OutputKind::Html(element) => return Ok(element),
|
OutputKind::Html(element) => return Ok(element),
|
||||||
OutputKind::Body(body) => body,
|
OutputKind::Body(body) => body,
|
||||||
OutputKind::Leafs(leafs) => HtmlElement::new(tag::body).with_children(leafs),
|
OutputKind::Leafs(leafs) => HtmlElement::new(tag::body).with_children(leafs),
|
||||||
};
|
};
|
||||||
Ok(HtmlElement::new(tag::html)
|
Ok(HtmlElement::new(tag::html).with_children(vec![head.into(), body.into()]))
|
||||||
.with_children(vec![head_element(info).into(), body.into()]))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Generate a `<head>` element.
|
/// 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)
|
HtmlElement::new(tag::head).with_children(children)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user