server: add option to inline CSS before slurping contents

This commit is contained in:
2025-01-25 16:09:05 -08:00
parent 906ebd73b2
commit 9842c8c99c
3 changed files with 87 additions and 6 deletions

View File

@@ -15,8 +15,8 @@ use crate::{
config::Config,
error::ServerError,
graphql::{Corpus, NewsPost, Tag, Thread, ThreadSummary},
thread_summary_from_row, AddOutlink, EscapeHtml, FrameImages, InlineStyle, Query, SanitizeHtml,
SlurpContents, ThreadSummaryRecord, Transformer, NEWSREADER_TAG_PREFIX,
thread_summary_from_row, AddOutlink, EscapeHtml, FrameImages, InlineRemoteStyle, Query,
SanitizeHtml, SlurpContents, ThreadSummaryRecord, Transformer, NEWSREADER_TAG_PREFIX,
NEWSREADER_THREAD_PREFIX,
};
@@ -196,6 +196,8 @@ pub async fn thread(
let body_tranformers: Vec<Box<dyn Transformer>> = vec![
Box::new(SlurpContents {
cacher,
// TODO: make this true when bulma is finally removed
inline_css: false,
site_selectors: hashmap![
"atmeta.com".to_string() => vec![
Selector::parse("div.entry-content").unwrap(),
@@ -223,6 +225,9 @@ pub async fn thread(
"ingowald.blog".to_string() => vec![
Selector::parse("article").unwrap(),
],
"jvns.ca".to_string() => vec![
Selector::parse("article").unwrap(),
],
"mitchellh.com".to_string() => vec![Selector::parse("div.w-full").unwrap()],
"natwelch.com".to_string() => vec![
Selector::parse("article div.prose").unwrap(),
@@ -234,6 +239,9 @@ pub async fn thread(
Selector::parse("span.story-byline").unwrap(),
Selector::parse("div.p").unwrap(),
],
"trofi.github.io".to_string() => vec![
Selector::parse("#content").unwrap(),
],
"www.redox-os.org".to_string() => vec![
Selector::parse("div.content").unwrap(),
],
@@ -245,12 +253,12 @@ pub async fn thread(
}),
Box::new(FrameImages),
Box::new(AddOutlink),
Box::new(EscapeHtml),
// TODO: causes doubling of images in cloudflare blogs
//Box::new(EscapeHtml),
Box::new(SanitizeHtml {
cid_prefix: "",
base_url: &link,
}),
Box::new(InlineStyle),
];
for t in body_tranformers.iter() {
if t.should_run(&link, &body) {