MYP3GIV3ML3ZX7WJEOS42VKT6AUW5FLCQAMIURGNWQQEBPYTOUEQC
use feed_rs::{
model::{Entry},
parser::parse,
};
use json_feed_model::{Author, Feed as JFeed, Item as JFItem, Version};
use lol_html::{element, html_content::ContentType, rewrite_str, RewriteStrSettings};
use feed_rs::parser::parse;
fn convert_smbc_entry(entry: &Entry, feed_title: &String) -> JFItem {
let mut item = JFItem::new();
item.set_id(&entry.id);
item.set_title(format!(
"{feed_title}: {}",
entry
.title
.as_ref()
.map(|t| t.content.clone())
.unwrap_or_default()
));
item.set_url(
entry
.links
.get(0)
.map(|l| l.href.clone())
.unwrap_or_else(|| "?? no url?".into()),
);
item.set_authors({
let mut authors = vec![];
for person in &entry.authors {
let mut a = Author::new();
a.set_name(person.name.clone());
authors.push(a);
}
authors
});
let new_content = entry
.summary
.as_ref()
.map(|t| t.content.clone())
.unwrap_or_else(|| "??? no summary html???".into());
let new_content =
rewrite_str(&new_content, create_rewrite_settings()).expect("rewrote");
item.set_content_html(new_content);
item
}
fn create_output_feed() -> JFeed {
let mut output = JFeed::new();
output.set_version(&Version::Version1_1);
output.set_title("lake feed");
output.set_home_page_url("https://nest.pijul.com/hdhoang/homes/laker/");
output
}
fn create_rewrite_settings() -> RewriteStrSettings<'static, 'static> {
let mut rules = vec![];
let remove_sizings = element!("img", |img| {
["height", "width", "srcset"].map(|attr| img.remove_attribute(&attr));
if let Some(mut unsized_src) = img.get_attribute("src") {
unsized_src = unsized_src.replace("&w", "&_");
unsized_src = unsized_src.replace("&h", "&_");
img.set_attribute("src", &unsized_src)
.expect("attr src is always valid")
}
Ok(())
});
rules.push(remove_sizings);
let append_title = element!("img[title]", |img| {
if let Some(title) = img.get_attribute("title") {
img.after(&format!("<p>{title}</p>"), ContentType::Html)
}
Ok(())
});
rules.push(append_title);
rules.push(element!(r#" img[src*="smbc-comics.com/"] "#, |img| {
if let Some(mut bonus_src) = img.get_attribute("src") {
bonus_src = bonus_src.replace(".png", "after.png");
img.after(&format!("<img src='{bonus_src}' />"), ContentType::Html);
};
Ok(())
}));
RewriteStrSettings {
element_content_handlers: rules,
..Default::default()
}
}
pavex_builder = { git = "https://github.com/LukeMathWalker/pavex", version = "0.1.0" }
pavex_runtime = { git = "https://github.com/LukeMathWalker/pavex", version = "0.1.0" }
]
[[package]]
name = "fs-err"
version = "2.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "64db3e262960f0662f43a6366788d5f10f7f244b8f7d7d987f560baf5ded5c50"
[[package]]
name = "futures-channel"
version = "0.3.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30bdd20c28fadd505d0fd6712cdfcb0d4b5648baf45faef7f852afb2399bb050"
dependencies = [
"futures-core",
]
[[package]]
name = "futures-core"
version = "0.3.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e5aa3de05362c3fb88de6531e6296e85cde7739cccad4b9dfeeb7f6ebce56bf"
[[package]]
name = "futures-sink"
version = "0.3.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21b20ba5a92e727ba30e72834706623d94ac93a725410b6a6b6fbc1b07f7ba56"
[[package]]
name = "futures-task"
version = "0.3.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a6508c467c73851293f390476d4491cf4d227dbabcd4170f3bb6044959b294f1"
[[package]]
name = "futures-util"
version = "0.3.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44fb6cb1be61cc1d2e43b262516aafcf63b241cffdb1d3fa115f91d9c7b09c90"
dependencies = [
"futures-core",
"futures-task",
"pin-project-lite",
"pin-utils",
name = "h2"
version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ca32592cf21ac7ccab1825cd87f6c9b3d9022c44d086172ed0966bec8af30be"
dependencies = [
"bytes",
"fnv",
"futures-core",
"futures-sink",
"futures-util",
"http",
"indexmap",
"slab",
"tokio",
"tokio-util",
"tracing",
]
[[package]]
name = "http"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75f43d41e26995c17e71ee126451dd3941010b0514a81a9d11f3b341debc2399"
dependencies = [
"bytes",
"fnv",
"itoa 1.0.3",
]
[[package]]
name = "http-body"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1"
dependencies = [
"bytes",
"http",
"pin-project-lite",
]
[[package]]
name = "httparse"
version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904"
[[package]]
name = "httpdate"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421"
[[package]]
name = "hyper"
version = "0.14.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02c929dc5c39e335a03c405292728118860721b10190d98c2a0f0efd5baafbac"
dependencies = [
"bytes",
"futures-channel",
"futures-core",
"futures-util",
"h2",
"http",
"http-body",
"httparse",
"httpdate",
"itoa 1.0.3",
"pin-project-lite",
"tokio",
"tower-service",
"tracing",
"want",
]
[[package]]
name = "pavex_builder"
version = "0.1.0"
source = "git+https://github.com/LukeMathWalker/pavex#1062b9fc057d7e7865a84fa183d9044ff47ba2b0"
dependencies = [
"anyhow",
"fs-err",
"indexmap",
"pavex_runtime",
"ron",
"serde",
]
[[package]]
name = "pavex_runtime"
version = "0.1.0"
source = "git+https://github.com/LukeMathWalker/pavex#1062b9fc057d7e7865a84fa183d9044ff47ba2b0"
dependencies = [
"anyhow",
"http",
"hyper",
"matchit",
]
[[package]]
name = "pin-project-lite"
version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116"
[[package]]
name = "pin-utils"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
[[package]]
name = "tokio"
version = "1.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89797afd69d206ccd11fb0ea560a44bbb87731d020670e79416d442919257d42"
dependencies = [
"autocfg",
"bytes",
"memchr",
"pin-project-lite",
"socket2",
]
[[package]]
name = "tokio-util"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cc463cd8deddc3770d20f9852143d50bf6094e640b485cb2e189a2099085ff45"
dependencies = [
"bytes",
"futures-core",
"futures-sink",
"pin-project-lite",
"tokio",
"tracing",
]
[[package]]
name = "tower-service"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52"
[[package]]
name = "tracing"
version = "0.1.36"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2fce9567bd60a67d08a16488756721ba392f24f29006402881e43b19aac64307"
dependencies = [
"cfg-if",
"pin-project-lite",
"tracing-core",
]
[[package]]
name = "tracing-core"
version = "0.1.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5aeea4303076558a00714b823f9ad67d58a3bbda1df83d8827d21193156e22f7"
dependencies = [
"once_cell",
]
[[package]]
name = "try-lock"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642"
[[package]]