web & server: finish initial tailwind rewrite
This commit is contained in:
@@ -1,8 +0,0 @@
|
||||
pre {
|
||||
background-color: var(--color-bg);
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
code {
|
||||
background-color: var(--color-bg-secondary);
|
||||
}
|
||||
@@ -117,26 +117,7 @@ struct InlineRemoteStyle<'a> {
|
||||
#[async_trait]
|
||||
impl<'a> Transformer for InlineRemoteStyle<'a> {
|
||||
async fn transform(&self, _: &Option<Url>, html: &str) -> Result<String, TransformError> {
|
||||
let css = concat!(
|
||||
"/* chrome-default.css */\n",
|
||||
include_str!("chrome-default.css"),
|
||||
"\n/* mvp.css */\n",
|
||||
include_str!("mvp.css"),
|
||||
"\n/* Xinu Specific overrides */\n",
|
||||
include_str!("custom.css"),
|
||||
);
|
||||
let inline_opts = InlineOptions {
|
||||
//inline_style_tags: true,
|
||||
//keep_style_tags: false,
|
||||
//keep_link_tags: true,
|
||||
base_url: self.base_url.clone(),
|
||||
//load_remote_stylesheets: true,
|
||||
//preallocate_node_capacity: 32,
|
||||
..InlineOptions::default()
|
||||
};
|
||||
|
||||
//info!("HTML:\n{html}");
|
||||
info!("base_url: {:#?}", self.base_url);
|
||||
Ok(
|
||||
match CSSInliner::options()
|
||||
.base_url(self.base_url.clone())
|
||||
@@ -160,10 +141,10 @@ impl Transformer for InlineStyle {
|
||||
let css = concat!(
|
||||
"/* chrome-default.css */\n",
|
||||
include_str!("chrome-default.css"),
|
||||
"\n/* mvp.css */\n",
|
||||
include_str!("mvp.css"),
|
||||
"\n/* Xinu Specific overrides */\n",
|
||||
include_str!("custom.css"),
|
||||
//"\n/* mvp.css */\n",
|
||||
//include_str!("mvp.css"),
|
||||
//"\n/* Xinu Specific overrides */\n",
|
||||
//include_str!("custom.css"),
|
||||
);
|
||||
let inline_opts = InlineOptions {
|
||||
inline_style_tags: true,
|
||||
@@ -288,13 +269,25 @@ impl SlurpContents {
|
||||
|
||||
#[async_trait]
|
||||
impl Transformer for SlurpContents {
|
||||
fn should_run(&self, link: &Option<Url>, _: &str) -> bool {
|
||||
fn should_run(&self, link: &Option<Url>, html: &str) -> bool {
|
||||
let mut will_slurp = false;
|
||||
if let Some(link) = link {
|
||||
return self.get_selectors(link).is_some();
|
||||
will_slurp = self.get_selectors(link).is_some();
|
||||
}
|
||||
false
|
||||
if !will_slurp && self.inline_css {
|
||||
return InlineStyle {}.should_run(link, html);
|
||||
}
|
||||
will_slurp
|
||||
}
|
||||
async fn transform(&self, link: &Option<Url>, html: &str) -> Result<String, TransformError> {
|
||||
if let Some(test_link) = link {
|
||||
// If SlurpContents is configured for inline CSS, but no
|
||||
// configuration found for this site, use the local InlineStyle
|
||||
// transform.
|
||||
if self.inline_css && self.get_selectors(test_link).is_none() {
|
||||
return InlineStyle {}.transform(link, html).await;
|
||||
}
|
||||
}
|
||||
let Some(link) = link else {
|
||||
return Ok(html.to_string());
|
||||
};
|
||||
@@ -303,7 +296,6 @@ impl Transformer for SlurpContents {
|
||||
};
|
||||
let cacher = self.cacher.lock().await;
|
||||
let body = if let Some(body) = cacher.get(link.as_str()) {
|
||||
info!("cache hit for {link}");
|
||||
String::from_utf8_lossy(&body).to_string()
|
||||
} else {
|
||||
let body = reqwest::get(link.as_str()).await?.text().await?;
|
||||
@@ -315,8 +307,17 @@ impl Transformer for SlurpContents {
|
||||
let body = if self.inline_css {
|
||||
let inner_body = Arc::clone(&body);
|
||||
let res = tokio::task::spawn_blocking(move || {
|
||||
let css = concat!(
|
||||
"/* chrome-default.css */\n",
|
||||
include_str!("chrome-default.css"),
|
||||
"\n/* vars.css */\n",
|
||||
include_str!("../../web/static/vars.css"),
|
||||
//"\n/* Xinu Specific overrides */\n",
|
||||
//include_str!("custom.css"),
|
||||
);
|
||||
let res = CSSInliner::options()
|
||||
.base_url(base_url)
|
||||
.extra_css(Some(std::borrow::Cow::Borrowed(css)))
|
||||
.build()
|
||||
.inline(&inner_body);
|
||||
|
||||
|
||||
@@ -15,9 +15,8 @@ use crate::{
|
||||
config::Config,
|
||||
error::ServerError,
|
||||
graphql::{Corpus, NewsPost, Tag, Thread, ThreadSummary},
|
||||
thread_summary_from_row, AddOutlink, EscapeHtml, FrameImages, InlineRemoteStyle, Query,
|
||||
SanitizeHtml, SlurpContents, ThreadSummaryRecord, Transformer, NEWSREADER_TAG_PREFIX,
|
||||
NEWSREADER_THREAD_PREFIX,
|
||||
thread_summary_from_row, AddOutlink, FrameImages, Query, SanitizeHtml, SlurpContents,
|
||||
ThreadSummaryRecord, Transformer, NEWSREADER_TAG_PREFIX, NEWSREADER_THREAD_PREFIX,
|
||||
};
|
||||
|
||||
pub fn is_newsreader_query(query: &Query) -> bool {
|
||||
@@ -196,8 +195,7 @@ 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,
|
||||
inline_css: true,
|
||||
site_selectors: hashmap![
|
||||
"atmeta.com".to_string() => vec![
|
||||
Selector::parse("div.entry-content").unwrap(),
|
||||
@@ -239,6 +237,14 @@ pub async fn thread(
|
||||
Selector::parse("span.story-byline").unwrap(),
|
||||
Selector::parse("div.p").unwrap(),
|
||||
],
|
||||
"theonion.com".to_string() => vec![
|
||||
// Single cartoon
|
||||
Selector::parse("article > div > div > figure").unwrap(),
|
||||
// Image at top of article
|
||||
Selector::parse("article > header > div > div > figure").unwrap(),
|
||||
// Article body
|
||||
Selector::parse("article .entry-content > *").unwrap(),
|
||||
],
|
||||
"trofi.github.io".to_string() => vec![
|
||||
Selector::parse("#content").unwrap(),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user