add twitter meta tags
This commit is contained in:
parent
96e39a6464
commit
93cbd88757
1 changed files with 22 additions and 4 deletions
26
src/main.rs
26
src/main.rs
|
@ -49,12 +49,12 @@ async fn create_page(source: &String, html: &String) -> Result<String, Status> {
|
|||
};
|
||||
|
||||
let illust = json::parse(data_meta.value().attr("content").unwrap()).unwrap();
|
||||
let target_url = match illust["illust"].entries().next() {
|
||||
let image = match illust["illust"].entries().next() {
|
||||
Some (j) => j.1["urls"]["regular"].as_str().unwrap().replace("pximg.net", "thebread.dev"),
|
||||
None => "https://http.cat/images/501.jpg".to_string(),
|
||||
};
|
||||
|
||||
let title_selector = match Selector::parse(r#"meta[name="og:title"]"#) {
|
||||
let title_selector = match Selector::parse(r#"meta[property="og:title"]"#) {
|
||||
Ok(sel) => sel,
|
||||
Err(_) => return Err(Status::InternalServerError),
|
||||
};
|
||||
|
@ -62,18 +62,36 @@ async fn create_page(source: &String, html: &String) -> Result<String, Status> {
|
|||
Some(meta) => meta.attr("content").unwrap(),
|
||||
None => "unknown title"
|
||||
};
|
||||
let desc_selector = match Selector::parse(r#"meta[property="og:description"]"#) {
|
||||
Ok(sel) => sel,
|
||||
Err(_) => return Err(Status::InternalServerError),
|
||||
};
|
||||
let desc_meta = match dom.select(&desc_selector).next() {
|
||||
Some(meta) => meta.attr("content").unwrap(),
|
||||
None => "unknown title"
|
||||
};
|
||||
|
||||
Ok(html! {
|
||||
(DOCTYPE)
|
||||
html lang="en" {
|
||||
head {
|
||||
meta charset="utf-8";
|
||||
|
||||
meta property="og:title" content=(title_meta);
|
||||
meta property="og:image" content=(target_url);
|
||||
meta property="og:image" content=(image);
|
||||
meta property="og:url" content=(source);
|
||||
meta property="og:type" content="article";
|
||||
meta property="og:site_name" content="pixiv";
|
||||
meta name="robots" content="max-image-preview:large";
|
||||
meta property="og:description" content=(desc_meta);
|
||||
|
||||
meta property="twitter:card" content="summary_large_image";
|
||||
meta property="twitter:site" content="@pixiv";
|
||||
meta property="twitter:url" content=(source);
|
||||
meta property="twitter:title" content=(title_meta);
|
||||
meta property="twitter:description" content=(desc_meta);
|
||||
meta property="twitter:image" content=(image);
|
||||
|
||||
|
||||
meta http-equiv="Refresh" content=(format!("0; url='{}'", source));
|
||||
}
|
||||
body {
|
||||
|
|
Loading…
Add table
Reference in a new issue